From f48ee1cc1ef5ed4ae3ef3c098a39d8807ea60008 Mon Sep 17 00:00:00 2001 From: vedant Date: Sat, 13 Sep 2025 20:27:08 +0530 Subject: [PATCH] Fix: Add type validation for sendStatus to prevent BigInt serialization error (#6756) - Add type checking in sendStatus() method to throw TypeError for non-number inputs - Prevents uncaught 'Do not know how to serialize a BigInt' error - Add test coverage for BigInt status code input - Maintains backward compatibility with existing error patterns Fixes #6756 --- lib/response.js | 3 +++ test/res.sendStatus.js | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/response.js b/lib/response.js index 7a2f0ecce56..873cd7af178 100644 --- a/lib/response.js +++ b/lib/response.js @@ -326,6 +326,9 @@ res.jsonp = function jsonp(obj) { */ res.sendStatus = function sendStatus(statusCode) { + if (typeof statusCode !== 'number') { + throw new TypeError('Invalid status code: ' + statusCode); + } var body = statuses.message[statusCode] || String(statusCode) this.status(statusCode); diff --git a/test/res.sendStatus.js b/test/res.sendStatus.js index b244cf9d173..10ee0c77c80 100644 --- a/test/res.sendStatus.js +++ b/test/res.sendStatus.js @@ -40,5 +40,17 @@ describe('res', function () { .get('/') .expect(500, /TypeError: Invalid status code/, done) }) + + it('should raise error for BigInt status code', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendStatus(200n) + }) + + request(app) + .get('/') + .expect(500, /TypeError.*Invalid status code/, done) + }) }) })