Skip to content

Commit 624f49f

Browse files
committed
docs: Document synthetic req contract for requestContextMiddleware
Clarify that directAccess uses a minimal synthetic request and that Express-only accessors are unavailable, addressing review feedback.
1 parent e45b7f7 commit 624f49f

4 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/Options/Definitions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ module.exports.ParseServerOptions = {
558558
},
559559
requestContextMiddleware: {
560560
env: 'PARSE_SERVER_REQUEST_CONTEXT_MIDDLEWARE',
561-
help: 'Options to customize the request context using inversion of control/dependency injection.',
561+
help: 'Options to customize the request context using inversion of control/dependency injection. Also applied on internal `directAccess` requests via a synthetic `req` that exposes only `config` and empty `headers`. Express-only accessors such as `req.get()`, `req.header()`, `req.ip`, and `req.body` are unavailable on that path.',
562562
},
563563
requestKeywordDenylist: {
564564
env: 'PARSE_SERVER_REQUEST_KEYWORD_DENYLIST',

src/Options/docs.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Options/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ export interface ParseServerOptions {
418418
/* Options to limit repeated requests to Parse Server APIs. This can be used to protect sensitive endpoints such as `/requestPasswordReset` from brute-force attacks or Parse Server as a whole from denial-of-service (DoS) attacks.<br><br>ℹ️ Mind the following limitations:<br>- rate limits applied per IP address; this limits protection against distributed denial-of-service (DDoS) attacks where many requests are coming from various IP addresses<br>- if multiple Parse Server instances are behind a load balancer or ran in a cluster, each instance will calculate it's own request rates, independent from other instances; this limits the applicability of this feature when using a load balancer and another rate limiting solution that takes requests across all instances into account may be more suitable<br>- this feature provides basic protection against denial-of-service attacks, but a more sophisticated solution works earlier in the request flow and prevents a malicious requests to even reach a server instance; it's therefore recommended to implement a solution according to architecture and use case.<br>- rate limits are matched against the REST API URL path (`requestPath`) and therefore apply to REST API routes only; they do not apply to GraphQL operations, which are all served under the single GraphQL endpoint path (`graphQLPath`, default `/graphql`) and are identified by the request payload rather than the URL. To rate limit GraphQL, either set a `requestPath` for the GraphQL endpoint path to throttle the entire GraphQL API, or use a GraphQL-aware rate limiting solution (for example a schema-directive-based rate limiter) for per-operation limits.
419419
:DEFAULT: [] */
420420
rateLimit: ?(RateLimitOptions[]);
421-
/* Options to customize the request context using inversion of control/dependency injection.*/
421+
/* Options to customize the request context using inversion of control/dependency injection. Also applied on internal `directAccess` requests via a synthetic `req` that exposes only `config` and empty `headers`. Express-only accessors such as `req.get()`, `req.header()`, `req.ip`, and `req.body` are unavailable on that path.*/
422422
requestContextMiddleware: ?(req: any, res: any, next: any) => void;
423423
/* If set to `true`, error details are removed from error messages in responses to client requests, and instead a generic error message is sent. Default is `true`.
424424
:DEFAULT: true */

src/ParseServerRESTController.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ function getAuth(options = {}, config) {
3232
/**
3333
* Apply requestContextMiddleware on a synthetic request so directAccess ops
3434
* get the same per-request DI as Express HTTP requests.
35+
*
36+
* Synthetic request contract (minimal supported fields only):
37+
* - `req.config` — Parse Server config (DI target)
38+
* - `req.headers` — empty object `{}` (no HTTP headers on this path)
39+
*
40+
* Express-only request properties and methods such as `req.get()`,
41+
* `req.header()`, `req.ip`, and `req.body` are unavailable. Middleware must
42+
* use only the supported fields above; this path intentionally does not add
43+
* partial Express compatibility.
3544
*/
3645
function applyRequestContextMiddleware(config) {
3746
if (typeof config.requestContextMiddleware !== 'function') {
@@ -50,6 +59,7 @@ function applyRequestContextMiddleware(config) {
5059
resolve();
5160
}
5261
};
62+
// Minimal synthetic req — see contract in JSDoc above.
5363
const req = { config, headers: {} };
5464
try {
5565
const maybePromise = config.requestContextMiddleware(req, {}, done);

0 commit comments

Comments
 (0)