Repository navigation
Conversation
23e4ea8 to
fbf0324
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Multipart writes double literal backslashes in uri and temporalDocument, causing MarkLogic to target identifiers different from those supplied by the caller.
1 open issue
What changed in this PR
This PR hardens the Node.js client’s multipart document writes against MIME header injection through document identifiers.
Changes:
- Validates
uriandtemporalDocument, rejecting carriage returns, line feeds, null bytes, and double quotes. - Adds regression tests for invalid identifiers and multipart header serialization, including backslashes.
| File | Description |
|---|---|
test-basic/documents-multipart-header-test.js |
Tests invalid-value rejection and serialized multipart headers. |
lib/documents.js |
Adds shared validation and backslash handling for multipart identifier parameters. |
Review effort: Balanced
…d raw into a quoted Content-Disposition parameter - a URI containing a double quote or CRLF injects MIME headers into the request
There was a problem hiding this comment.
🟡 Changes recommended
The rejection tests do not cover multipart streaming, leaving the new validation guard without regression coverage against CR/LF injection through streaming writes.
1 open issue
1 resolved since last review
Review effort: Balanced
| } | ||
| } | ||
|
|
||
| function validateContentDispositionValue(value) { |
There was a problem hiding this comment.
addDocumentParts() validates uri and temporalDocument here, but at line 1433 it also appends addWriteConfig(document, hasUri, content, headers, '; ') directly to disposition.
In multipart mode (sep === '; ', isBody === false), addWriteConfig() interpolates document.extension, document.directory (unencoded when isBody === false at line 1310), and document.versionId (line 1320) directly into Content-Disposition without quoting or validation. Because validatePartHeaders() in lib/requester.js only checks for [\r\n\0], passing ; or " in directory, extension, or versionId (e.g., versionId: '1; filename="/hijacked.json"' or directory: '/a; filename="/hijacked.json"') still injects arbitrary Content-Disposition parameters on the same header line.
We should validate extension, directory, and versionId in addWriteConfig() (rejecting [;\r\n\0"] or quoting and passing through validateContentDispositionValue).
| operation.inputSender = singleRequester; | ||
| break; | ||
| case 'multipart': | ||
| validatePartHeaders(operation.requestPartList); |
There was a problem hiding this comment.
In multipartRequester(), when operation.bindingParam is set (lines 427–484), operation.requestPartList is undefined, so validatePartHeaders(operation.requestPartList) is a no-op. In that branch, attachment keys (filename: key at lines 450–465) and bindingParam.key (line 441) are passed into form.append(), which writes them into Content-Disposition headers without rejecting \r, \n, \0, or ". We should validate bindingParam.key and attachment keys as well.
prgs-rsingh
left a comment
There was a problem hiding this comment.
Good fix for uri, temporalDocument, and CR/LF/NUL in requestPartList / requestDocument. Left two inline comments regarding same-line Content-Disposition parameter injection via addWriteConfig() (directory, extension, versionId) and the operation.bindingParam multipart path.
| headers['If-Match'] = versionId; | ||
| } else { | ||
| writeConfig += sep+'versionId='+versionId; | ||
| writeConfig += sep+'versionId='+validateContentDispositionValue(versionId); |
There was a problem hiding this comment.
validateContentDispositionValue() only rejects [\r\n\0"], which is sufficient for uri and temporalDocument because they are wrapped in double quotes (filename="...").
Here in addWriteConfig(), however, extension, directory, and versionId are emitted unquoted (; extension=...; directory=...; versionId=...). In an unquoted Content-Disposition parameter, ; is the parameter delimiter itself — so a value containing ; without quotes (e.g., versionId: '1; category=metadata' or directory: '/poc/; category=metadata') still injects extra Content-Disposition parameters.
Since these three parameters are unquoted, please also reject ; (e.g., /[\r\n\0";]/) when validating extension, directory, and versionId.
prgs-rsingh
left a comment
There was a problem hiding this comment.
Thanks for adding validateBindingParam() and updating addWriteConfig(). One small follow-up on addWriteConfig(): because extension, directory, and versionId are unquoted in Content-Disposition, their validator also needs to reject ; (/[\r\n\0";]/) so ; cannot inject additional parameters without quotes.
…d raw into a quoted Content-Disposition parameter - a URI containing a double quote or CRLF injects MIME headers into the request

Summary
In
lib/documents.js(addDocumentParts), documenturiandtemporalDocumentwere concatenated directly into theContent-Dispositionheader of multipart/mixed batch write payloads. A URI containing double quotes (") or CRLF (\r\n) allowed injection of arbitrary MIME headers or forged parts to hijack document write targets (CWE-113 / CWE-929).Changes
quoteHeaderParam()validation inlib/documents.jsto reject any values containing\r,\n,\0, or".Errorimmediately (rejection is required because MarkLogic Server does not unescape backslashes\"insidefilename="...").uriandtemporalDocument.test-basic/verifying that inputs with quotes, CRLF, or null bytes are rejected prior to network transmission.Verification