Skip to content

JS: treat the base argument of URL as tainted in request forgery queries - #23089

Open
ebickle wants to merge 4 commits into
github:mainfrom
ebickle:js/request-forgery-url-base
Open

ebickle wants to merge 4 commits into
github:mainfrom
ebickle:js/request-forgery-url-base

Conversation

@ebickle

@ebickle ebickle commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

new URL(input, base) only propagated taint from input. A user-controlled base with a relative input decides the host of the resulting URL, so it can reach a request sink but was missed.

Extend isAdditionalRequestForgeryStep to also propagate from the second argument, for both the global URL and require("url").URL. The base is not propagated when every possible value of the first argument is a URL object or a string with an authority (scheme://), since the base cannot affect the result in those cases.

Fixes #23066
Follows #5630, which added the first-argument step.

Implementation note
A first argument with a non-special scheme and no // (for example mailto: or data:) conservatively keeps the base tainted. Handling these would need additional regular expressions for little benefit, and such code is rare: new URL('data:text/plain,hello', req.query.input) is equivalent to new URL('data:text/plain,hello'), so the base argument serves no purpose.

`new URL(input, base)` only propagated taint from `input`.
A user-controlled `base` with a relative `input` decides the host of
the resulting URL, so it can reach a request sink but was missed.

Extend `isAdditionalRequestForgeryStep` to also propagate from the
second argument, for both the global `URL` and `require("url").URL`.
@ebickle
ebickle requested a review from a team as a code owner November 10, 2026 20:58
Copilot AI adaptive review requested due to automatic review settings November 10, 2026 20:58

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

Unconditional URL-base taint propagation causes false positives for absolute URLs, and negative regression tests plus an assessed DCA evaluation of the final change are still needed.

2 open issues
What changed in this PR

Extends JavaScript request-forgery analysis to track user-controlled URL bases, addressing the missed flows described in #23066.

Changes:

  • Propagates taint from both arguments of global and Node.js-imported URL constructors.
  • Adds server-side regression cases and updates expected results.
  • Documents the expanded server-side and client-side detection.
File Description
javascript/​ql/​test/​query-tests/​Security/​CWE-918/​serverSide.js Adds base-argument cases for both constructor forms.
javascript/​ql/​test/​query-tests/​Security/​CWE-918/​RequestForgery.expected Records new alerts and flow paths; adjusts shifted locations.
javascript/​ql/​lib/​semmle/​javascript/​security/​dataflow/​RequestForgeryCustomizations.qll Extends constructor taint propagation to argument 1.
javascript/​ql/​lib/​change-notes/​2026-11-10-request-forgery-url-base.md Announces the request-forgery detection improvement.

Review effort: Max (auto)

The base argument of `new URL(...)` is ignored when the first argument is
already an absolute URL, either a string with a scheme or another `URL`
object. Skip the base taint step in those cases.

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

Unresolved critical flaws drop attacker-controlled base taint for same-scheme URL strings and mixed URL-object/relative inputs, causing missed request-forgery alerts.

3 open issues
2 previously missed issues

In code that hasn't changed since last review

Medium severity Resolve aliased absolute strings before applying base-taint checks

javascript/​ql/​lib/​semmle/​javascript/​security/​dataflow/​RequestForgeryCustomizations.qll:88

An absolute string stored in a variable, such as const input = 'https://fixed.example/path', has no getStringValue() at the constructor argument. The new step therefore reports request forgery for new URL(input, req.query.base) even though the base cannot change the destination. Resolve definitely base-independent strings through local flow, preserving taint for relative or unknown alternatives, and add an aliased-string negative test.

Medium severity Recognize node:url imports in URL constructor lookups

javascript/​ql/​lib/​semmle/​javascript/​security/​dataflow/​RequestForgeryCustomizations.qll:113

When a database imports only require('node:url').URL, API::moduleImport("url") has no matching import root, so the new base-taint step misses this constructor. Include node:url in both constructor lookups, for example with API::moduleImport(["url", "node:url"]), and add a regression without any bare url import. The helper at line 80 needs the same update.

1 resolved since last review

Review effort: Max (adaptive)

…fore dropping base taint

Also treat same-scheme inputs like `https:/path` as relative, and add tests.

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 absolute-URL check can ignore concatenated relative branches, incorrectly suppressing base taint and missing request-forgery alerts.

1 open issue
3 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.

🟡 Changes recommended

An absolute parameter default incorrectly suppresses base taint even when a caller supplies a relative path, causing critical request-forgery false negatives.

1 open issue
1 resolved since last review

Review effort: Balanced

*/
private predicate isAbsoluteUrl(DataFlow::Node nd) {
forex(DataFlow::Node origin |
origin = nd.getAPredecessor*() and not exists(origin.getAPredecessor())

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JavaScript: Request forgery taint blocked by base argument of "new URL(url, base)"

2 participants