Bounds what the formidable parse in api/api.js is allowed to write to disk, and removes whatever it wrote that no handler consumed.
api/api.js parses every POST body with formidable, before the request is routed or authorized. formidable writes multipart parts and raw application/octet-stream bodies to disk, so without a gate any POST carrying such a body leaves a file behind - including requests to paths that no handler serves. This module provides:
- parseOptions: formidable options that allow a file to be written only where a plugin declared that the path reads params.files
- discardUploads: removal of the files a request left behind
- Description:
Bounds what the formidable parse in api/api.js is allowed to write to disk, and removes whatever it wrote that no handler consumed.
api/api.js parses every POST body with formidable, before the request is routed or authorized. formidable writes multipart parts and raw application/octet-stream bodies to disk, so without a gate any POST carrying such a body leaves a file behind - including requests to paths that no handler serves. This module provides:
- parseOptions: formidable options that allow a file to be written only where a plugin declared that the path reads params.files
- discardUploads: removal of the files a request left behind
- Source:
Methods
(inner) discardUploads(params) → {void}
- Description:
Remove the files formidable wrote for this request.
Handlers that consume an upload unlink it themselves, so in the normal case these are already gone and the unlink is a no-op. What is left is every request that was rejected before reaching a handler at all, which is not enumerable at the rejection sites - rights.js alone rejects in 63 places.
Only the snapshot from trackUploads is touched, never params.files, so a handler substituting a path cannot redirect this at another file.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
params |
object | request params |
Returns:
- Type
- void
(inner) findDeclaration(uploadPaths, reqPath) → {object|null}
- Description:
Find the declaration a plugin registered for this path, if any.
Matching is exact: a declaration for /i must not let /i/anything through, otherwise declaring the SDK write endpoint would reopen the whole /i tree.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
uploadPaths |
Array | plugins.uploadPaths |
reqPath |
string | normalized request path |
Returns:
the declaration, or null when uploads are not allowed
- Type
- object | null
(inner) normalizePath(url, installPathopt) → {string}
- Description:
Strip the query string and the installation subpath from a request url. requestProcessor strips the subpath before routing, so it has to be stripped here too or uploads would be refused on subdirectory installs.
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
url |
string | request url, query string included |
|
installPath |
string |
<optional> |
installation subpath (common.config.path) |
Returns:
the path as requestProcessor will see it
- Type
- string
(inner) parseOptions(url, installPathopt, uploadPathsopt) → {object}
- Description:
formidable options restricting what this request may write to disk.
Returns the options to merge into the IncomingForm options: an empty object where uploads are expected, and otherwise the entries that suppress them. Both suppressions are needed and cover different parsers -
filteris only consulted for multipart parts, while formidable's octetstream plugin creates its file directly via _newFile() and never callsfilter, so the only way to stop a raw body reaching disk is to leave that plugin out.The remaining parsers are kept enabled either way, so urlencoded and json bodies still populate params.qstring exactly as before.
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
url |
string | request url, query string included |
|
installPath |
string |
<optional> |
installation subpath (common.config.path) |
uploadPaths |
Array |
<optional> |
plugins.uploadPaths, the declared upload paths |
Returns:
options to merge into the IncomingForm options
- Type
- object
(inner) trackUploads(params, files) → {void}
- Description:
Record the paths formidable produced for this request, so they can be removed later without trusting params.files.
The snapshot is taken before any handler runs, because a handler may repoint params.files[x].path at something else entirely - crash_symbolication points it at files shipped with the plugin when serving populator data, which must never be deleted.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
params |
object | request params |
files |
object | the files formidable parsed |
Returns:
- Type
- void