Skip to content

JS: Explicitly Mark Sinon Package as Non RegExp #19854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 24, 2025
Merged

Conversation

Napalys
Copy link
Contributor

@Napalys Napalys commented Jun 23, 2025

The following pull request explicitly marks Sinon’s package match calls as non-RegExp in order to avoid false positives.

@Napalys Napalys marked this pull request as ready for review June 24, 2025 08:21
@Copilot Copilot AI review requested due to automatic review settings June 24, 2025 08:21
@Napalys Napalys requested a review from a team as a code owner June 24, 2025 08:21
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ensures that sinon.match() is explicitly recognized as a non-RegExp operation in the security queries, avoiding false positives when analyzing test code.

  • Adds example usages of sinon.match(…) in two CWE-020 test suites to verify they’re not flagged as regex operations.
  • Updates the QL predicate in Regexp.qll to treat sinon.match calls as non‐match objects.
  • Documents the change in change-notes/2025-06-20-sinon.md.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
javascript/ql/test/query-tests/Security/CWE-020/MissingRegExpAnchor/tst.js New test asserting that sinon.match("https://a.b.com") is non-regexp
javascript/ql/test/query-tests/Security/CWE-020/IncompleteHostnameRegExp/tst-IncompleteHostnameRegExp.js Added similar sinon.match test in the incomplete-hostname suite
javascript/ql/lib/semmle/javascript/Regexp.qll Expanded isUsedAsNonMatchObject to include sinon.match calls
javascript/ql/lib/change-notes/2025-06-20-sinon.md Noted that sinon.match() is no longer misidentified
Comments suppressed due to low confidence (3)

javascript/ql/lib/semmle/javascript/Regexp.qll:1001

  • We’ve added support for CommonJS require('sinon'); consider adding a test case (and predicate clause if needed) to cover ES module imports (e.g. import sinon from 'sinon') so sinon.match calls aren’t flagged in that scenario.
    or

javascript/ql/test/query-tests/Security/CWE-020/MissingRegExpAnchor/tst.js:5

  • Indentation appears to mix tabs and spaces. Please align with the project's indentation style (e.g., use two spaces) to maintain consistency.
	sinon.assert.calledWith(postStub.firstCall, sinon.match(megacliteUrl));

javascript/ql/test/query-tests/Security/CWE-020/IncompleteHostnameRegExp/tst-IncompleteHostnameRegExp.js:64

  • [nitpick] This require is inside a callback block and uses mixed indentation; consider moving it to the top of the file and aligning with the project's spacing rules for clarity.
	const sinon = require('sinon');

@Napalys Napalys merged commit 2218a98 into github:main Jun 24, 2025
15 checks passed
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.

2 participants