JavaScript: Exclude debug npm package from js/log-injection sinks#3
Open
kiro-agent[bot] wants to merge 1 commit into
Open
JavaScript: Exclude debug npm package from js/log-injection sinks#3kiro-agent[bot] wants to merge 1 commit into
kiro-agent[bot] wants to merge 1 commit into
Conversation
mrigankpawagi
pushed a commit
that referenced
this pull request
Jun 20, 2026
When CODEQL_EXTRACTOR_GO_OPTION_EXTRACT_TESTS=true is set, the Go extractor was incorrectly skipping internal test files (package foo) at repository roots when the project contains nested test packages. Root Cause: The extractor selected package variants by longest ID string, but this heuristic fails when nested packages have tests. For a package like "github.com/go-git/go-git/v6", packages.Load returns multiple variants: 1. "github.com/go-git/go-git/v6" (19 files, production only) 2. "github.com/go-git/go-git/v6 [github.com/go-git/go-git/v6.test]" (39 files, production + 20 root tests) ← Should select this 3. "github.com/go-git/go-git/v6 [github.com/go-git/go-git/v6/plumbing/format/packfile.test]" (19 files, test dependency) ← Was incorrectly selected (longest string) The old logic selected variant #3 (76 chars) over #2 (68 chars), causing 20 root test files to be missing from the database. Fix: Replace string length comparison with a better heuristic that prefers: 1. Exact test packages (e.g., "pkg [pkg.test]") over nested dependencies 2. Packages with more Syntax nodes (more files to extract) 3. String length as a tiebreaker This ensures the extractor selects the variant with the most complete test coverage, particularly for root-level internal tests. Testing: - Added comprehensive unit tests covering the selection logic - Tests simulate the real-world go-git scenario - All tests pass Impact: Root-level external tests (package foo_test) were already extracted correctly. This fix ensures internal tests (package foo) at the root are now also extracted when they exist alongside nested test packages. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
8481e5e to
f22d076
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request was created by @kiro-agent on behalf of @mrigankpawagi 👻
Comment with /kiro fix to address specific feedback or /kiro all to address everything.
Learn about Kiro Web
Summary
This PR improves the
js/log-injectionquery by excluding calls to thedebugnpm package from being considered as log injection sinks.Problem
MRVA (Multi-Repository Variant Analysis) on the top-100 JavaScript repositories revealed many false positives from calls to the
debugnpm package. For example, 10 out of 12 alerts inmicrosoft/playwrightwere fromdebug.*calls in test/proxy code. Thedebugpackage is a development debugging utility that:DEBUGenvironment variable is explicitly setFlagging these as log injection sinks generates noise without security value.
Changes
Modified
LoggingSinkclass injavascript/ql/lib/semmle/javascript/security/dataflow/LogInjectionQuery.qll:this = any(LoggerCall console).getAMessageComponent()exists()pattern that excludes calls matchingAPI::moduleImport("debug").getReturn().getACall()Test case - Added a test in
javascript/ql/test/query-tests/Security/CWE-117/logInjectionGood.jsdemonstrating thatdebug()calls are not flagged.Change note - Added
javascript/ql/src/change-notes/2025-06-07-log-injection-exclude-debug.md.MRVA Validation
debugpackage usage across many repositoriesWhy this is correct
The
debugnpm package (https://www.npmjs.com/package/debug) is fundamentally different from production loggers:DEBUGenv var