Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix(sendStatus): prevent invalid numeric status codes
Ensure status codes in sendStatus() are valid integers between 100-999, addressing PR feedback about oversized numeric values passing validation.
  • Loading branch information
Dhairya3391 committed Oct 16, 2025
commit d715914dce914024330dadc16a98602dd9ee2c7c
9 changes: 8 additions & 1 deletion lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,14 @@ res.jsonp = function jsonp(obj) {
res.sendStatus = function sendStatus(statusCode) {
// Prevent BigInt status codes from causing obscure errors
if (typeof statusCode === 'bigint') {
throw new TypeError('Status code must be an integer');
throw new TypeError('Status code must be an integer number');
}
if (typeof statusCode !== 'number' || !Number.isInteger(statusCode) || statusCode < 100 || statusCode > 999) {
if (!Number.isInteger(statusCode)) {
throw new TypeError(`Invalid status code: ${JSON.stringify(statusCode)}. Status code must be an integer.`);
} else {
throw new RangeError(`Invalid status code: ${JSON.stringify(statusCode)}. Must be between 100 and 999.`);
}
}

var body = statuses.message[statusCode] || String(statusCode)
Expand Down