Skip to content

Commit 34836ff

Browse files
docs: update external docs (expressjs#2161)
Co-authored-by: Create or Update Pull Request Action <create-or-update-pull-request@users.noreply.github.com>
1 parent 7d1613e commit 34836ff

4 files changed

Lines changed: 131 additions & 44 deletions

File tree

_includes/readmes/body-parser.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,14 @@ $ npm install body-parser
5151
## API
5252

5353
```js
54+
// Import all parsers
5455
const bodyParser = require('body-parser')
56+
57+
// Or import individual parsers directly
58+
const json = require('body-parser/json')
59+
const urlencoded = require('body-parser/urlencoded')
60+
const raw = require('body-parser/raw')
61+
const text = require('body-parser/text')
5562
```
5663

5764
The `bodyParser` object exposes various factories to create middlewares. All
@@ -221,8 +228,8 @@ encoding of the request. The parsing can be aborted by throwing an error.
221228

222229
Returns middleware that only parses `urlencoded` bodies and only looks at
223230
requests where the `Content-Type` header matches the `type` option. This
224-
parser accepts only UTF-8 encoding of the body and supports automatic
225-
inflation of `gzip`, `br` (brotli) and `deflate` encodings.
231+
parser accepts only UTF-8 and ISO-8859-1 encodings of the body and supports
232+
automatic inflation of `gzip`, `br` (brotli) and `deflate` encodings.
226233

227234
A new `body` object containing the parsed data is populated on the `request`
228235
object after the middleware (i.e. `req.body`). This object will contain

_includes/readmes/cors.md

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
[![Build Status][github-actions-ci-image]][github-actions-ci-url]
66
[![Test Coverage][coveralls-image]][coveralls-url]
77

8-
CORS is a [Node.js](https://nodejs.org/en/) package for providing a [Connect](https://github.com/senchalabs/connect)/[Express](https://expressjs.com/) middleware that can be used to enable [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS) with various options.
8+
CORS is a [Node.js](https://nodejs.org/en/) middleware for [Express](https://expressjs.com/)/[Connect](https://github.com/senchalabs/connect) that sets [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS) response headers. These headers tell browsers which origins can read responses from your server.
9+
10+
> [!IMPORTANT]
11+
> **How CORS Works:** This package sets response headers—it doesn't block requests. CORS is enforced by browsers: they check the headers and decide if JavaScript can read the response. Non-browser clients (curl, Postman, other servers) ignore CORS entirely. See the [MDN CORS guide](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS) for details.
912
1013
* [Installation](#installation)
1114
* [Usage](#usage)
@@ -16,6 +19,7 @@ CORS is a [Node.js](https://nodejs.org/en/) package for providing a [Connect](ht
1619
* [Enabling CORS Pre-Flight](#enabling-cors-pre-flight)
1720
* [Customizing CORS Settings Dynamically per Request](#customizing-cors-settings-dynamically-per-request)
1821
* [Configuration Options](#configuration-options)
22+
* [Common Misconceptions](#common-misconceptions)
1923
* [License](#license)
2024
* [Original Author](#original-author)
2125

@@ -38,14 +42,15 @@ var express = require('express')
3842
var cors = require('cors')
3943
var app = express()
4044

45+
// Adds headers: Access-Control-Allow-Origin: *
4146
app.use(cors())
4247

4348
app.get('/products/:id', function (req, res, next) {
44-
res.json({msg: 'This is CORS-enabled for all origins!'})
49+
res.json({msg: 'Hello'})
4550
})
4651

4752
app.listen(80, function () {
48-
console.log('CORS-enabled web server listening on port 80')
53+
console.log('web server listening on port 80')
4954
})
5055
```
5156

@@ -56,12 +61,13 @@ var express = require('express')
5661
var cors = require('cors')
5762
var app = express()
5863

64+
// Adds headers: Access-Control-Allow-Origin: *
5965
app.get('/products/:id', cors(), function (req, res, next) {
60-
res.json({msg: 'This is CORS-enabled for a Single Route'})
66+
res.json({msg: 'Hello'})
6167
})
6268

6369
app.listen(80, function () {
64-
console.log('CORS-enabled web server listening on port 80')
70+
console.log('web server listening on port 80')
6571
})
6672
```
6773

@@ -79,12 +85,13 @@ var corsOptions = {
7985
optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
8086
}
8187

88+
// Adds headers: Access-Control-Allow-Origin: http://example.com, Vary: Origin
8289
app.get('/products/:id', cors(corsOptions), function (req, res, next) {
83-
res.json({msg: 'This is CORS-enabled for only example.com.'})
90+
res.json({msg: 'Hello'})
8491
})
8592

8693
app.listen(80, function () {
87-
console.log('CORS-enabled web server listening on port 80')
94+
console.log('web server listening on port 80')
8895
})
8996
```
9097

@@ -118,12 +125,13 @@ var corsOptions = {
118125
}
119126
}
120127

128+
// Adds headers: Access-Control-Allow-Origin: <matched origin>, Vary: Origin
121129
app.get('/products/:id', cors(corsOptions), function (req, res, next) {
122-
res.json({msg: 'This is CORS-enabled for an allowed domain.'})
130+
res.json({msg: 'Hello'})
123131
})
124132

125133
app.listen(80, function () {
126-
console.log('CORS-enabled web server listening on port 80')
134+
console.log('web server listening on port 80')
127135
})
128136
```
129137

@@ -141,13 +149,13 @@ var express = require('express')
141149
var cors = require('cors')
142150
var app = express()
143151

144-
app.options('/products/:id', cors()) // enable pre-flight request for DELETE request
152+
app.options('/products/:id', cors()) // preflight for DELETE
145153
app.del('/products/:id', cors(), function (req, res, next) {
146-
res.json({msg: 'This is CORS-enabled for all origins!'})
154+
res.json({msg: 'Hello'})
147155
})
148156

149157
app.listen(80, function () {
150-
console.log('CORS-enabled web server listening on port 80')
158+
console.log('web server listening on port 80')
151159
})
152160
```
153161

@@ -181,28 +189,30 @@ Here’s an example that handles both public routes and restricted, credential-s
181189
var dynamicCorsOptions = function(req, callback) {
182190
var corsOptions;
183191
if (req.path.startsWith('/auth/connect/')) {
192+
// Access-Control-Allow-Origin: http://mydomain.com, Access-Control-Allow-Credentials: true, Vary: Origin
184193
corsOptions = {
185-
origin: 'http://mydomain.com', // Allow only a specific origin
186-
credentials: true, // Enable cookies and credentials
194+
origin: 'http://mydomain.com',
195+
credentials: true
187196
};
188197
} else {
189-
corsOptions = { origin: '*' }; // Allow all origins for other routes
198+
// Access-Control-Allow-Origin: *
199+
corsOptions = { origin: '*' };
190200
}
191201
callback(null, corsOptions);
192202
};
193203

194204
app.use(cors(dynamicCorsOptions));
195205

196206
app.get('/auth/connect/twitter', function (req, res) {
197-
res.send('CORS dynamically applied for Twitter authentication.');
207+
res.send('Hello');
198208
});
199209

200210
app.get('/public', function (req, res) {
201-
res.send('Public data with open CORS.');
211+
res.send('Hello');
202212
});
203213

204214
app.listen(80, function () {
205-
console.log('CORS-enabled web server listening on port 80')
215+
console.log('web server listening on port 80')
206216
})
207217
```
208218

@@ -235,7 +245,19 @@ The default configuration is the equivalent of:
235245
}
236246
```
237247

238-
For details on the effect of each CORS header, read [this](https://web.dev/articles/cross-origin-resource-sharing) article.
248+
## Common Misconceptions
249+
250+
### "CORS blocks requests from disallowed origins"
251+
252+
**No.** Your server receives and processes every request. CORS headers tell the browser whether JavaScript can read the response—not whether the request is allowed.
253+
254+
### "CORS protects my API from unauthorized access"
255+
256+
**No.** CORS is not access control. Any HTTP client (curl, Postman, another server) can call your API regardless of CORS settings. Use authentication and authorization to protect your API.
257+
258+
### "Setting `origin: 'http://example.com'` means only that domain can access my server"
259+
260+
**No.** It means browsers will only let JavaScript from that origin read responses. The server still responds to all requests.
239261

240262
## License
241263

_includes/readmes/session.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,26 @@ For a list of stores, see [compatible session stores](#compatible-session-stores
4949
Settings object for the session ID cookie. The default value is
5050
`{ path: '/', httpOnly: true, secure: false, maxAge: null }`.
5151

52+
In addition to providing a static object, you can also pass a callback function to dynamically generate the cookie options for each request. The callback receives the `req` object as its argument and should return an object containing the cookie settings.
53+
54+
```js
55+
var app = express()
56+
app.use(session({
57+
secret: 'keyboard cat',
58+
resave: false,
59+
saveUninitialized: true,
60+
cookie: function(req) {
61+
var match = req.url.match(/^\/([^/]+)/);
62+
return {
63+
path: match ? '/' + match[1] : '/',
64+
httpOnly: true,
65+
secure: req.secure || false,
66+
maxAge: 60000
67+
}
68+
}
69+
}))
70+
```
71+
5272
The following are options that can be set in this object.
5373

5474
##### cookie.domain
@@ -130,6 +150,7 @@ By default, this is `false`.
130150
- `'lax'` will set the `SameSite` attribute to `Lax` for lax same site enforcement.
131151
- `'none'` will set the `SameSite` attribute to `None` for an explicit cross-site cookie.
132152
- `'strict'` will set the `SameSite` attribute to `Strict` for strict same site enforcement.
153+
- `'auto'` will set the `SameSite` attribute to `None` for secure connections and `Lax` for non-secure connections.
133154

134155
More information about the different enforcement levels can be found in
135156
[the specification][rfc-6265bis-03-4.1.2.7].
@@ -141,6 +162,14 @@ the future. This also means many clients may ignore this attribute until they un
141162
that requires that the `Secure` attribute be set to `true` when the `SameSite` attribute has been
142163
set to `'none'`. Some web browsers or other clients may be adopting this specification.
143164

165+
The `cookie.sameSite` option can also be set to the special value `'auto'` to have
166+
this setting automatically match the determined security of the connection. When the connection
167+
is secure (HTTPS), the `SameSite` attribute will be set to `None` to enable cross-site usage.
168+
When the connection is not secure (HTTP), the `SameSite` attribute will be set to `Lax` for
169+
better security while maintaining functionality. This is useful when the Express `"trust proxy"`
170+
setting is properly setup to simplify development vs production configuration, particularly
171+
for SAML authentication scenarios.
172+
144173
##### cookie.secure
145174

146175
Specifies the `boolean` value for the `Secure` `Set-Cookie` attribute. When truthy,

en/resources/contributing.md

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -301,37 +301,62 @@ visibility or maintainer input.
301301
This document outlines security procedures and general policies for the Express
302302
project.
303303

304-
* [Reporting a Bug](#reporting-a-bug)
304+
* [Reporting a Bug or Security Vulnerability](#reporting-a-bug-or-security-vulnerability)
305305
* [Disclosure Policy](#disclosure-policy)
306306
* [Comments on this Policy](#comments-on-this-policy)
307+
* [The Express Threat Model](#the-express-threat-model)
307308

308-
### Reporting a Bug
309+
### Reporting a Bug or Security Vulnerability
309310

310-
The Express team and community take all security bugs in Express seriously.
311-
Thank you for improving the security of Express. We appreciate your efforts and
312-
responsible disclosure and will make every effort to acknowledge your
313-
contributions.
311+
> [!IMPORTANT]
312+
> Before reporting a vulnerability, please review the [Express Threat Model](#the-express-threat-model) to check if the issue falls within Express's security scope.
314313
315-
Report security bugs by emailing `express-security@lists.openjsf.org`.
314+
The Express team and community take all security vulnerabilities seriously.
315+
Thank you for improving the security of Express and related projects.
316+
We appreciate your efforts in responsible disclosure and will make every effort
317+
to acknowledge your contributions.
316318

317-
To ensure the timely response to your report, please ensure that the entirety
318-
of the report is contained within the email body and not solely behind a web
319-
link or an attachment.
319+
A [Security triage team member](https://github.com/expressjs/security-wg#security-triage-team-expressjssecurity-triage)
320+
or [the repo captain](https://github.com/expressjs/discussions/blob/master/docs/contributing/captains_and_committers.md)
321+
will acknowledge your report as soon as possible.
322+
These timelines may extend when our triage
323+
volunteers are away on holiday, particularly at the end of the year.
320324

321-
The lead maintainer will acknowledge your email within 48 hours, and will send a
322-
more detailed response within 48 hours indicating the next steps in handling
323-
your report. After the initial reply to your report, the security team will
325+
After the initial reply to your report, the security team will
324326
endeavor to keep you informed of the progress towards a fix and full
325327
announcement, and may ask for additional information or guidance.
326328

327-
Report security bugs in third-party modules to the person or team maintaining
328-
the module.
329+
> [!NOTE]
330+
> You can find more information about our process in [this guide](https://github.com/expressjs/security-wg/blob/main/docs/incident_response_plan.md)
329331
330-
### Pre-release Versions
331332

332-
Alpha and Beta releases are unstable and **not suitable for production use**.
333-
Vulnerabilities found in pre-releases should be reported according to the [Reporting a Bug](#reporting-a-bug) section.
334-
Due to the unstable nature of the branch it is not guaranteed that any fixes will be released in the next pre-release.
333+
#### Reporting Security Bugs via GitHub Security Advisory (Preferred)
334+
335+
The preferred way to report security vulnerabilities is through
336+
[GitHub Security Advisories](https://github.com/advisories).
337+
This allows us to collaborate on a fix while maintaining the
338+
confidentiality of the report.
339+
340+
To report a vulnerability
341+
([docs](https://docs.github.com/en/code-security/security-advisories/guidance-on-reporting-and-writing-information-about-vulnerabilities/privately-reporting-a-security-vulnerability)):
342+
1. Visit the **Security** tab of the affected repository on GitHub.
343+
2. Click **Report a vulnerability** and follow the provided steps.
344+
345+
This process applies to any repositories within the Express ecosystem.
346+
If you are unsure whether a repository falls under this policy,
347+
feel free to reach out via email.
348+
349+
#### Reporting via Email
350+
351+
If you prefer, you can also report security issues by emailing `express-security@lists.openjsf.org`.
352+
353+
To ensure a timely response, please include all relevant details directly in the email body rather than linking to external sources or attaching files.
354+
355+
The lead maintainer will acknowledge your email within 48 hours and provide an initial response outlining the next steps. The security team will keep you updated on the progress and may request additional details.
356+
357+
#### Third-Party Modules
358+
359+
If the security issue pertains to a third-party module that is not directly maintained within the Express ecosystem, please report it to the maintainers of that module.
335360

336361
### Disclosure Policy
337362

@@ -344,15 +369,19 @@ involving the following steps:
344369
* Prepare fixes for all releases still under maintenance. These fixes will be
345370
released as fast as possible to npm.
346371

347-
### The Express Threat Model
348-
349-
We are currently working on a new version of the security model, the most updated version can be found [here](https://github.com/expressjs/security-wg/blob/main/docs/ThreatModel.md)
350-
351372
### Comments on this Policy
352373

353374
If you have suggestions on how this process could be improved please submit a
354375
pull request.
355376

377+
### The Express Threat Model
378+
379+
The Express threat model defines the boundaries of what the framework considers its security responsibility. It establishes which elements are trusted (such as the developer, the runtime environment, and application code) versus untrusted (such as data from network connections). Issues arising from trusted elements are considered out of scope, while Express is responsible for safely handling untrusted data.
380+
381+
Many commonly reported concerns fall outside Express's security scope and are the responsibility of the application developer. Such as prototype pollution from unsanitized user input, misconfigured static file serving, or issues in third-party dependencies.
382+
383+
For complete details, see the [Express Threat Model](https://github.com/expressjs/security-wg/blob/main/docs/ThreatModel.md).
384+
356385
----
357386
# Contributing to Expressjs.com {#expressjs-website-contributing}
358387

0 commit comments

Comments
 (0)