Skip to content

Bug Report: Cannot set property query of #<IncomingMessage> error when using express-mongo-sanitize #202

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

Open
amir-mansoor opened this issue May 2, 2025 · 5 comments

Comments

@amir-mansoor
Copy link

amir-mansoor commented May 2, 2025

When adding the express-mongo-sanitize middleware to my Express.js application, I encounter the following error:
Cannot set property query of # which has only a getter
This error appears on every screen/request after applying the middleware.
i install the middleware:
npm install express-mongo-sanitize

add it to the express app

import express from 'express';
import mongoSanitize from 'express-mongo-sanitize';

const app = express();
app.use(mongoSanitize());```

Expected Behavior:
The middleware should sanitize req.body, req.query, and req.params without throwing an error.

Current Behavior:
It throws the some error on every request
@rob3rtotrasatti
Copy link

rob3rtotrasatti commented May 6, 2025

I have the same problem in my Express JS application with TypeScript.

The issue seems to be here: code

Library Code:
req[key] = target;

When the express-mongo-sanitize module try to reassign the value on the request, that is based on IncomingMessage class from Node JS.

I think the class is immutable and therefore there is this error.

There are other issues related to this problems. I think for the moment the compatibility of this module with Express 5 is not a priority: issue

I'm following the discussion waiting for advice.

@as3305100
Copy link

Same error is also happen with me

@as3305100
Copy link

When the solution will come

@christian-schwaderer
Copy link

It seems like this happens after updating to Express 5. Experiencing the same issue. To be fair, it says that "express-mongo-sanitize" is a "Express 4.x middleware". But it would be nice anyway to get a fix 🙏

@as3305100
Copy link

as3305100 commented May 13, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants