Skip to content

Commit

Permalink
Adding input sanitization
Browse files Browse the repository at this point in the history
  • Loading branch information
hgorges committed Aug 24, 2024
1 parent c5d31cb commit 569e9c5
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"ajv": "^8.17.1",
"ajv-errors": "^3.0.0",
"ajv-formats": "^3.0.1",
"ajv-sanitizer": "^1.2.1",
"bcrypt": "^5.1.1",
"connect-flash": "^0.1.1",
"connect-redis": "^7.1.1",
Expand Down
2 changes: 2 additions & 0 deletions src/config/ajv.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Ajv from 'ajv';
import addFormats from 'ajv-formats';
import ajvErrors from 'ajv-errors';
import ajvSanitizer from 'ajv-sanitizer';

export default (): Ajv => {
const ajv = new Ajv({
Expand All @@ -10,6 +11,7 @@ export default (): Ajv => {

addFormats(ajv);
ajvErrors(ajv);
ajvSanitizer(ajv);

return ajv;
};
1 change: 1 addition & 0 deletions src/types/ajv-sanitizer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'ajv-sanitizer';
1 change: 1 addition & 0 deletions src/validators/validateLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const loginSchema: JSONSchemaType<{
properties: {
username: {
type: 'string',
sanitize: (data: string) => data.trim().toLowerCase(),
},
password: {
type: 'string',
Expand Down
1 change: 1 addition & 0 deletions src/validators/validatePasswordReset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const passwordResetSchema: JSONSchemaType<{
email: {
type: 'string',
format: 'email',
sanitize: (data: string) => data.trim().toLowerCase(),
},
_csrf: {
type: 'string',
Expand Down
4 changes: 4 additions & 0 deletions src/validators/validateSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,24 @@ const settingsSchema: JSONSchemaType<{
minLength: 3,
maxLength: 20,
pattern: '^[a-zA-Z0-9]*$',
sanitize: (data: string) => data.trim().toLowerCase(),
},
first_name: {
type: 'string',
minLength: 1,
maxLength: 20,
sanitize: (data: string) => data.trim(),
},
last_name: {
type: 'string',
minLength: 1,
maxLength: 20,
sanitize: (data: string) => data.trim(),
},
email: {
type: 'string',
format: 'email',
sanitize: (data: string) => data.trim().toLowerCase(),
},
password: {
type: 'string',
Expand Down
4 changes: 4 additions & 0 deletions src/validators/validateSignup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,24 @@ const signupSchema: JSONSchemaType<{
minLength: 3,
maxLength: 20,
pattern: '^[a-zA-Z0-9]*$',
sanitize: (data: string) => data.trim().toLowerCase(),
},
first_name: {
type: 'string',
minLength: 1,
maxLength: 20,
sanitize: (data: string) => data.trim(),
},
last_name: {
type: 'string',
minLength: 1,
maxLength: 20,
sanitize: (data: string) => data.trim(),
},
email: {
type: 'string',
format: 'email',
sanitize: (data: string) => data.trim().toLowerCase(),
},
password: {
type: 'string',
Expand Down

0 comments on commit 569e9c5

Please sign in to comment.