Merge pull request #34 from ragusa-it/sentinel-input-limits-8405607204449411064
🛡️ Sentinel: [Medium] Add input length limits to Contact form
This commit was merged in pull request #34.
This commit is contained in:
@@ -9,6 +9,7 @@ import { sanitizeInput, isValidEmail } from "../utils/security";
|
|||||||
import styles from "./Contact.module.css";
|
import styles from "./Contact.module.css";
|
||||||
|
|
||||||
const NAME_MAX_LENGTH = 100;
|
const NAME_MAX_LENGTH = 100;
|
||||||
|
const EMAIL_MAX_LENGTH = 254;
|
||||||
const SUBJECT_MAX_LENGTH = 200;
|
const SUBJECT_MAX_LENGTH = 200;
|
||||||
const MESSAGE_MAX_LENGTH = 5000;
|
const MESSAGE_MAX_LENGTH = 5000;
|
||||||
|
|
||||||
@@ -53,6 +54,8 @@ export function Contact() {
|
|||||||
|
|
||||||
if (!formData.email.trim()) {
|
if (!formData.email.trim()) {
|
||||||
newErrors.email = "Required";
|
newErrors.email = "Required";
|
||||||
|
} else if (formData.email.length > EMAIL_MAX_LENGTH) {
|
||||||
|
newErrors.email = `Max ${EMAIL_MAX_LENGTH} characters`;
|
||||||
} else if (!isValidEmail(formData.email)) {
|
} else if (!isValidEmail(formData.email)) {
|
||||||
newErrors.email = "Invalid email";
|
newErrors.email = "Invalid email";
|
||||||
}
|
}
|
||||||
@@ -170,6 +173,7 @@ export function Contact() {
|
|||||||
value={formData.name}
|
value={formData.name}
|
||||||
onChange={(e) => handleChange("name", e.target.value)}
|
onChange={(e) => handleChange("name", e.target.value)}
|
||||||
error={errors.name}
|
error={errors.name}
|
||||||
|
maxLength={NAME_MAX_LENGTH}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
@@ -180,6 +184,7 @@ export function Contact() {
|
|||||||
value={formData.email}
|
value={formData.email}
|
||||||
onChange={(e) => handleChange("email", e.target.value)}
|
onChange={(e) => handleChange("email", e.target.value)}
|
||||||
error={errors.email}
|
error={errors.email}
|
||||||
|
maxLength={EMAIL_MAX_LENGTH}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
@@ -189,6 +194,7 @@ export function Contact() {
|
|||||||
value={formData.subject}
|
value={formData.subject}
|
||||||
onChange={(e) => handleChange("subject", e.target.value)}
|
onChange={(e) => handleChange("subject", e.target.value)}
|
||||||
error={errors.subject}
|
error={errors.subject}
|
||||||
|
maxLength={SUBJECT_MAX_LENGTH}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Textarea
|
<Textarea
|
||||||
@@ -199,6 +205,7 @@ export function Contact() {
|
|||||||
onChange={(e) => handleChange("message", e.target.value)}
|
onChange={(e) => handleChange("message", e.target.value)}
|
||||||
error={errors.message}
|
error={errors.message}
|
||||||
rows={6}
|
rows={6}
|
||||||
|
maxLength={MESSAGE_MAX_LENGTH}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
Reference in New Issue
Block a user