Skip to content

MLE-33479: Bugcrowd: node-client-api: the document URI is interpolated raw into a quoted Content-Disposition parameter - a URI containing a double quote or CRLF injects MIME headers into the request - #1133

Open
vishwach wants to merge 2 commits into
developfrom
MLE-33479

Conversation

@vishwach

@vishwach vishwach commented Nov 17, 2026 •

Copy link
Copy Markdown

Summary

In lib/documents.js (addDocumentParts), document uri and temporalDocument were concatenated directly into the Content-Disposition header 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

  • Added quoteHeaderParam() validation in lib/documents.js to reject any values containing \r, \n, \0, or ".
  • Throws a descriptive Error immediately (rejection is required because MarkLogic Server does not unescape backslashes \" inside filename="...").
  • Applied validation to both uri and temporalDocument.
  • Added unit tests in test-basic/ verifying that inputs with quotes, CRLF, or null bytes are rejected prior to network transmission.

Verification

  • All 3 regression tests, targeted lint, and whitespace checks pass

@vishwach
vishwach force-pushed the MLE-33479 branch 2 times, most recently from 23e4ea8 to fbf0324 Compare November 17, 2026 17:35
@vishwach
vishwach marked this pull request as ready for review November 18, 2026 05:04
Copilot AI balanced review requested due to automatic review settings November 18, 2026 05:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 uri and temporalDocument, 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

Comment thread lib/documents.js Resolved
…d raw into a quoted Content-Disposition parameter - a URI containing a double quote or CRLF injects MIME headers into the request

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the multipart header-injection hardening changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Comment thread lib/documents.js
}
}

function validateContentDispositionValue(value) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread lib/requester.js
operation.inputSender = singleRequester;
break;
case 'multipart':
validatePartHeaders(operation.requestPartList);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 prgs-rsingh left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread lib/documents.js Outdated
headers['If-Match'] = versionId;
} else {
writeConfig += sep+'versionId='+versionId;
writeConfig += sep+'versionId='+validateContentDispositionValue(versionId);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 prgs-rsingh left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants