-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
temporarily disabled input validation #3684
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,6 @@ function createValidateSelectedSitesField(requiredFields, allowId = false) { | |
throw new Error("_id field is not allowed"); | ||
} | ||
|
||
// Check for required fields | ||
if (!requiredFields.every((field) => field in value)) { | ||
throw new Error( | ||
`Missing required fields: ${requiredFields | ||
|
@@ -48,6 +47,16 @@ function createValidateSelectedSitesField(requiredFields, allowId = false) { | |
); | ||
} | ||
|
||
const isValidId = isMongoId(value._id); | ||
if (!isValidId && allowId) { | ||
throw new Error("_id must be a valid MongoDB ObjectId"); | ||
} | ||
|
||
const isValidSiteId = isMongoId(value.site_id); | ||
if (!isValidSiteId && !allowId) { | ||
throw new Error("site_id must be a valid MongoDB ObjectId"); | ||
} | ||
|
||
function validateNumericFields(fields) { | ||
for (const field of fields) { | ||
if (field in value) { | ||
|
@@ -80,6 +89,9 @@ function createValidateSelectedSitesField(requiredFields, allowId = false) { | |
(typeof value[field] !== "string" || value[field].trim() === "") | ||
) { | ||
throw new Error(`${field} must be a non-empty string`); | ||
} else if (!(field in value)) { | ||
// Log missing field | ||
throw new Error(`Field "${field}" is missing`); | ||
} | ||
} | ||
return true; | ||
|
@@ -99,11 +111,6 @@ function createValidateSelectedSitesField(requiredFields, allowId = false) { | |
} | ||
} | ||
|
||
const isValidSiteId = "site_id" in value && isMongoId(value.site_id); | ||
if (!isValidSiteId) { | ||
throw new Error("site_id must be a valid MongoDB ObjectId"); | ||
} | ||
|
||
const numericValid = validateNumericFields([ | ||
"latitude", | ||
"longitude", | ||
|
@@ -112,11 +119,10 @@ function createValidateSelectedSitesField(requiredFields, allowId = false) { | |
]); | ||
|
||
const stringValid = validateStringFields(["name", "search_name"]); | ||
|
||
const tags = value && value.site_tags; | ||
const tagValid = validateTags(tags); | ||
|
||
return numericValid && stringValid && tagValid && isValidSiteId; | ||
return numericValid && stringValid && tagValid; | ||
}; | ||
} | ||
|
||
|
@@ -386,14 +392,14 @@ router.post( | |
return Array.isArray(value); | ||
}) | ||
.withMessage("the selected_sites should be an array"), | ||
body("selected_sites.*") | ||
.optional() | ||
.custom( | ||
createValidateSelectedSitesField(["_id", "search_name", "name"], true) | ||
) | ||
.withMessage( | ||
"Invalid selected_sites format. Verify required fields (latitude, longitude, search_name, name, approximate_latitude, approximate_longitude), numeric fields (latitude, longitude, approximate_latitude, approximate_longitude, search_radius if present), string fields (name, search_name), and ensure site_tags is an array of strings." | ||
), | ||
// body("selected_sites.*") | ||
// .optional() | ||
// .custom( | ||
// createValidateSelectedSitesField(["_id", "search_name", "name"], true) | ||
// ) | ||
// .withMessage( | ||
// "Invalid selected_sites format. Verify required fields (latitude, longitude, search_name, name, approximate_latitude, approximate_longitude), numeric fields (latitude, longitude, approximate_latitude, approximate_longitude, search_radius if present), string fields (name, search_name), and ensure site_tags is an array of strings." | ||
// ), | ||
], | ||
]), | ||
createPreferenceController.upsert | ||
|
@@ -592,9 +598,6 @@ router.patch( | |
// .optional() | ||
// .custom( | ||
// createValidateSelectedSitesField(["_id", "search_name", "name"], true) | ||
// ) | ||
// .withMessage( | ||
// "Invalid selected_sites format. Verify required fields (latitude, longitude, search_name, name, approximate_latitude, approximate_longitude), numeric fields (latitude, longitude, approximate_latitude, approximate_longitude, search_radius if present), string fields (name, search_name), and ensure site_tags is an array of strings." | ||
// ), | ||
], | ||
]), | ||
|
@@ -791,14 +794,14 @@ router.put( | |
return Array.isArray(value); | ||
}) | ||
.withMessage("the selected_sites should be an array"), | ||
body("selected_sites.*") | ||
.optional() | ||
.custom( | ||
createValidateSelectedSitesField(["_id", "search_name", "name"], true) | ||
) | ||
.withMessage( | ||
"Invalid selected_sites format. Verify required fields (latitude, longitude, search_name, name, approximate_latitude, approximate_longitude), numeric fields (latitude, longitude, approximate_latitude, approximate_longitude, search_radius if present), string fields (name, search_name), and ensure site_tags is an array of strings." | ||
), | ||
// body("selected_sites.*") | ||
// .optional() | ||
// .custom( | ||
// createValidateSelectedSitesField(["_id", "search_name", "name"], true) | ||
// ) | ||
// .withMessage( | ||
// "Invalid selected_sites format. Verify required fields (latitude, longitude, search_name, name, approximate_latitude, approximate_longitude), numeric fields (latitude, longitude, approximate_latitude, approximate_longitude, search_radius if present), string fields (name, search_name), and ensure site_tags is an array of strings." | ||
// ), | ||
Comment on lines
+797
to
+804
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assess Impact of Disabled Validation in Update Route The validation for |
||
], | ||
]), | ||
createPreferenceController.update | ||
|
@@ -961,14 +964,14 @@ router.post( | |
return Array.isArray(value); | ||
}) | ||
.withMessage("the selected_sites should be an array"), | ||
body("selected_sites.*") | ||
.optional() | ||
.custom( | ||
createValidateSelectedSitesField(["_id", "search_name", "name"], true) | ||
) | ||
.withMessage( | ||
"Invalid selected_sites format. Verify required fields (latitude, longitude, search_name, name, approximate_latitude, approximate_longitude), numeric fields (latitude, longitude, approximate_latitude, approximate_longitude, search_radius if present), string fields (name, search_name), and ensure site_tags is an array of strings." | ||
), | ||
// body("selected_sites.*") | ||
// .optional() | ||
// .custom( | ||
// createValidateSelectedSitesField(["_id", "search_name", "name"], true) | ||
// ) | ||
// .withMessage( | ||
// "Invalid selected_sites format. Verify required fields (latitude, longitude, search_name, name, approximate_latitude, approximate_longitude), numeric fields (latitude, longitude, approximate_latitude, approximate_longitude, search_radius if present), string fields (name, search_name), and ensure site_tags is an array of strings." | ||
// ), | ||
Comment on lines
+967
to
+974
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review Disabled Validation in Create Route Disabling the validation for |
||
], | ||
]), | ||
createPreferenceController.create | ||
|
@@ -1194,12 +1197,12 @@ router.post( | |
.bail() | ||
.notEmpty() | ||
.withMessage("selected_sites should not be empty"), | ||
body("selected_sites.*").custom( | ||
createValidateSelectedSitesField( | ||
["site_id", "search_name", "name"], | ||
false | ||
) | ||
), | ||
// body("selected_sites.*").custom( | ||
// createValidateSelectedSitesField( | ||
// ["site_id", "search_name", "name"], | ||
// false | ||
// ) | ||
// ), | ||
Comment on lines
+1200
to
+1205
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential Risks with Disabled Validation in 'addSelectedSites' By commenting out the validation for |
||
], | ||
]), | ||
setJWTAuth, | ||
|
@@ -1233,11 +1236,11 @@ router.put( | |
.customSanitizer((value) => { | ||
return ObjectId(value); | ||
}), | ||
body("selected_site") | ||
.custom(createValidateSelectedSitesField([], false)) | ||
.withMessage( | ||
"Invalid selected site data. Verify required fields and data types." | ||
), | ||
// body("selected_site") | ||
// .custom(createValidateSelectedSitesField([], false)) | ||
// .withMessage( | ||
// "Invalid selected site data. Verify required fields and data types." | ||
// ), | ||
Comment on lines
+1239
to
+1243
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Evaluate Disabled Validation in 'updateSelectedSite' The absence of validation for updating a selected site could result in unintended data modifications. Please consider the necessity of this change and whether additional checks are needed elsewhere. |
||
], | ||
]), | ||
setJWTAuth, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider the Risks of Disabling Validation for 'selected_sites'
Commenting out the validation for
selected_sites.*
removes important checks on user input. While temporarily disabling validation might be necessary, please be mindful of potential issues such as processing invalid data or introducing security vulnerabilities. It's advisable to ensure that other safeguards are in place to handle unvalidated input appropriately.