CodeQL fix: limit parameter sizes

This commit is contained in:
mikiher 2025-10-15 18:54:29 +03:00
parent 888190a6be
commit 3f6162f53c
2 changed files with 19 additions and 6 deletions

View file

@ -286,13 +286,21 @@ module.exports.timestampToSeconds = (timestamp) => {
*
* @param {any} value - Query parameter value
* @param {string} defaultValue - Default value if undefined/null
* @returns {string|null} String value or null if invalid (array)
* @param {number} maxLength - Optional maximum length (defaults to 10000 to prevent ReDoS attacks)
* @returns {string|null} String value or null if invalid (array or too long)
*/
module.exports.getQueryParamAsString = (value, defaultValue = '') => {
module.exports.getQueryParamAsString = (value, defaultValue = '', maxLength = 1000) => {
// Explicitly reject arrays to prevent type confusion
if (Array.isArray(value)) {
return null
}
// Return default for undefined/null, otherwise return the value
return value == null ? defaultValue : value
// Return default for undefined/null
if (value == null) {
return defaultValue
}
// Reject excessively long strings to prevent ReDoS attacks
if (typeof value === 'string' && value.length > maxLength) {
return null
}
return value
}