Review a pull request: validation helpers
Not solvedNew validators for sign-up and search. Some regexes take exponential time on the right input. Find them.
- Level
- Practitioner
- Estimated time
- ~20 min
- Points
- 0/75 pts
- Questions
- 0/0 answered
- OWASP
- A06:2025
- OWASP
- A10:2025
- CWE
- CWE-1333
- CWE
- CWE-625
src/lib/validate.ts0/3 found
| // Input validation helpers used by the signup and search endpoints | ||
| export const isUsername = (s: string) => /^[a-z0-9_]{3,32}$/.test(s) | ||
| + | export function isEmail(s: string) { | |
| + | return /^([a-zA-Z0-9_.-]+)+@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(s) | |
| + | } | |
| + | ||
| + | export function isSlug(s: string) { | |
| + | return s.length <= 64 && /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(s) | |
| + | } | |
| + | ||
| + | export function isTagList(s: string) { | |
| + | return /^(\w+\s?)*$/.test(s) | |
| + | } | |
| + | ||
| + | export function searchNotes(notes: Note[], query: string) { | |
| + | const pattern = new RegExp(query, 'i') | |
| + | return notes.filter(n => pattern.test(n.body)) | |
| + | } |
Click a line number to flag a defect. The review code appears when every defect is flagged with no false positives.