You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update 5x API docs with missing 4x changes (#1886)
* Include 4.18 API doc updates in 5.x
5c98ee4
Co-authored-by: Douglas Christopher Wilson <doug@somethingdoug.com>
* Copy acceptsLanguages documentation improvements to 5.x
#1402
Co-authored-by: Jon Ege Ronnenberg <jon.ronnenberg@gmail.com>
* Add warning boxes to {app,res}.render
5e918ea
Co-authored-by: Douglas Christopher Wilson <doug@somethingdoug.com>
* Copy warning around securing locals to 5.x
fcaca7f
Co-authored-by: Douglas Christopher Wilson <doug@somethingdoug.com>
* Copy res.cookie `partitioned` option docs
#1456
Co-authored-by: Rich Hodgkins <rhodgkins@gmail.com>
* Update req.body to point to built-in middleware
a5ca5b0
Co-Authored-By: Douglas Wilson <doug@somethingdoug.com>
* Copy setting multiple cookies example to 5.x
#1063
Co-Authored-By: Mo <hematy61@gmail.com>
---------
Co-authored-by: krzysdz <krzysdz@users.noreply.github.com>
Co-authored-by: Douglas Christopher Wilson <doug@somethingdoug.com>
Co-authored-by: Jon Ege Ronnenberg <jon.ronnenberg@gmail.com>
Co-authored-by: Rich Hodgkins <rhodgkins@gmail.com>
Co-authored-by: Mo <hematy61@gmail.com>
Copy file name to clipboardExpand all lines: _includes/api/en/5x/req-body.md
+7-8Lines changed: 7 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
Contains key-value pairs of data submitted in the request body.
4
4
By default, it is `undefined`, and is populated when you use body-parsing middleware such
5
-
as [body-parser](https://www.npmjs.org/package/body-parser) and [multer](https://www.npmjs.org/package/multer).
5
+
as [`express.json()`](#express.json) or [`express.urlencoded()`](#express.urlencoded).
6
6
7
7
<divclass="doc-box doc-warn"markdown="1">
8
8
As `req.body`'s shape is based on user-controlled input, all properties and values in this object are untrusted and should be validated before trusting. For example, `req.body.foo.toString()` may fail in multiple ways, for example `foo` may not be there or may not be a string, and `toString` may not be a function and instead a string or other user-input.
@@ -11,15 +11,14 @@ As `req.body`'s shape is based on user-controlled input, all properties and valu
11
11
The following example shows how to use body-parsing middleware to populate `req.body`.
12
12
13
13
```js
14
-
constapp=require('express')()
15
-
constbodyParser=require('body-parser')
16
-
constmulter=require('multer') // v1.0.5
17
-
constupload=multer() // for parsing multipart/form-data
14
+
constexpress=require('express')
18
15
19
-
app.use(bodyParser.json()) // for parsing application/json
20
-
app.use(bodyParser.urlencoded({ extended:true })) // for parsing application/x-www-form-urlencoded
| `domain` | String | Domain name for the cookie. Defaults to the domain name of the app.
10
-
| `encode` | Function | A synchronous function used for cookie value encoding. Defaults to `encodeURIComponent`.
11
-
| `expires` | Date | Expiry date of the cookie in GMT. If not specified or set to 0, creates a session cookie.
12
-
| `httpOnly` | Boolean | Flags the cookie to be accessible only by the web server.
13
-
| `maxAge` | Number | Convenient option for setting the expiry time relative to the current time in milliseconds.
14
-
| `path` | String | Path for the cookie. Defaults to "/".
15
-
| `secure` | Boolean | Marks the cookie to be used with HTTPS only.
16
-
| `signed` | Boolean | Indicates if the cookie should be signed.
17
-
| `sameSite` | Boolean or String | Value of the "SameSite" **Set-Cookie** attribute. More information at [https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00#section-4.1.1](https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00#section-4.1.1).
| `domain` | String | Domain name for the cookie. Defaults to the domain name of the app.
10
+
| `encode` | Function | A synchronous function used for cookie value encoding. Defaults to `encodeURIComponent`.
11
+
| `expires` | Date | Expiry date of the cookie in GMT. If not specified or set to 0, creates a session cookie.
12
+
| `httpOnly` | Boolean | Flags the cookie to be accessible only by the web server.
13
+
| `maxAge` | Number | Convenient option for setting the expiry time relative to the current time in milliseconds.
14
+
| `path` | String | Path for the cookie. Defaults to "/".
15
+
| `partitioned` | Boolean | Indicates that the cookie should be stored using partitioned storage. See [Cookies Having Independent Partitioned State (CHIPS)](https://developer.mozilla.org/en-US/docs/Web/Privacy/Partitioned_cookies) for more details.
16
+
| `priority` | String | Value of the "Priority" **Set-Cookie** attribute.
17
+
| `secure` | Boolean | Marks the cookie to be used with HTTPS only.
18
+
| `signed` | Boolean | Indicates if the cookie should be signed.
19
+
| `sameSite` | Boolean or String | Value of the "SameSite" **Set-Cookie** attribute. More information at [https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00#section-4.1.1](https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00#section-4.1.1).
18
20
19
21
<divclass="doc-box doc-notice"markdown="1">
20
22
All `res.cookie()` does is set the HTTP `Set-Cookie` header with the options provided.
Copy file name to clipboardExpand all lines: _includes/api/en/5x/res-download.md
+12-1Lines changed: 12 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,17 @@ The optional `options` argument is supported by Express v4.16.0 onwards.
6
6
7
7
Transfers the file at `path` as an "attachment". Typically, browsers will prompt the user for download.
8
8
By default, the `Content-Disposition` header "filename=" parameter is derived from the `path` argument, but can be overridden with the `filename` parameter.
9
-
If `path` is relative, then it will be based on the current working directory of the process.
9
+
If `path` is relative, then it will be based on the current working directory of the process or
10
+
the `root` option, if provided.
11
+
12
+
<divclass="doc-box doc-warn"markdown="1">
13
+
This API provides access to data on the running file system. Ensure that either (a) the way in
14
+
which the `path` argument was constructed is secure if it contains user input or (b) set the `root`
15
+
option to the absolute path of a directory to contain access within.
16
+
17
+
When the `root` option is provided, Express will validate that the relative path provided as
18
+
`path` will resolve within the given `root` option.
19
+
</div>
10
20
11
21
The following table provides details on the `options` parameter.
12
22
@@ -19,6 +29,7 @@ The optional `options` argument is supported by Express v4.16.0 onwards.
|`maxAge`| Sets the max-age property of the `Cache-Control` header in milliseconds or a string in [ms format](https://www.npmjs.org/package/ms)| 0 | 4.16+ |
32
+
|`root`| Root directory for relative filenames.|| 4.18+ |
22
33
|`lastModified`| Sets the `Last-Modified` header to the last modified date of the file on the OS. Set `false` to disable it.| Enabled | 4.16+ |
23
34
|`headers`| Object containing HTTP headers to serve with the file. The header `Content-Disposition` will be overridden by the `filename` argument.|| 4.16+ |
24
35
|`dotfiles`| Option for serving dotfiles. Possible values are "allow", "deny", "ignore".| "ignore" | 4.16+ |
Copy file name to clipboardExpand all lines: _includes/api/en/5x/res-render.md
+7-1Lines changed: 7 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,13 @@ The `view` argument is a string that is the file path of the view file to render
10
10
11
11
For more information, see [Using template engines with Express](/{{page.lang}}/guide/using-template-engines.html).
12
12
13
-
{% include admonitions/note.html content="The `view` argument performs file system operations like reading a file from disk and evaluating Node.js modules, and as so for security reasons should not contain input from the end-user." %}
13
+
{% include admonitions/warning.html content="The `view` argument performs file system operations like reading a file from disk and evaluating Node.js modules, and as so for security reasons should not contain input from the end-user." %}
14
+
15
+
{% include admonitions/warning.html content="The `locals` object is used by view engines to render a response. The object
16
+
keys may be particularly sensitive and should not contain user-controlled
17
+
input, as it may affect the operation of the view engine or provide a path to
18
+
cross-site scripting. Consult the documentation for the used view engine for
19
+
additional considerations." %}
14
20
15
21
{% include admonitions/caution.html content="The local variable `cache` enables view caching. Set it to `true`,
16
22
to cache the view during development; view caching is enabled in production by default." %}
0 commit comments