codeql: exclude bundled clang18 toolchain headers from extraction to fix FP alert #1881#44767
Closed
codeql: exclude bundled clang18 toolchain headers from extraction to fix FP alert #1881#44767
Conversation
…P alert #1881 Agent-Logs-Url: https://github.com/envoyproxy/envoy/sessions/1a58adf5-6945-42ed-a136-287eaf4bfd4a Co-authored-by: phlax <454682+phlax@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix CodeQL alert suppression for cpp/new-free-mismatch
codeql: exclude bundled clang18 toolchain headers from extraction to fix FP alert #1881
Apr 30, 2026
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.
cpp/new-free-mismatchalert #1881 is a structural false positive caused by CodeQL extracting the bundled libc++ headers frombin/clang18.1.8/as project sources (viaBAZEL_LLVM_PATH). The previouspaths-ignoreapproach incodeql-config.ymlhad no effect because that filter only matches an alert's primary location — fornew-free-mismatchthat's the allocation site in Envoy code, not<vector>which only appears as the sink in the dataflow path.Changes
codeql-push.ymlandcodeql-daily.yml: addenv:on theInitialize CodeQLstep to suppress extraction at source rather than filtering after the fact:EXCLUDE_HEADER_PATTERNSprevents the toolchain headers from entering the database entirely;WIP_IGNORE_SYSTEM_HEADERSis a belt-and-braces extractor flag for any system headers that slip through via other paths. Thepaths-ignoreincodeql-config.ymlis retained as a backstop.Actual suppression of alert #1881 can only be confirmed on the next daily run against
main; a greenCodeQL/pushon this PR validates the workflow remains functional.Original prompt
Background
CodeQL alert #1881 (
cpp/new-free-mismatch, primary location reportedly inside<vector>) is a structural false positive coming from the bundled libc++ headers in the clang toolchain that the CodeQL workflows download (bin/clang18.1.8/include/c++/v1/...).A previous attempt to suppress it via
paths-ignorein.github/codeql/codeql-config.yml(commitd7bc39f82046a525b600bf5f8cc6ee63471bfe70, PR #44609) had no effect on the alert. The most likely reason is thatpaths-ignoreis matched against an alert's primary location only, while forcpp/new-free-mismatchthe primary location is the allocation site (often re-rooted into Envoy code through templatedstd::vectorinstantiations), with<vector>only appearing as a sink in the dataflow path.paths-ignoreis also known to be unreliable for C/C++ when system/standard-library headers are involved.Goal
Stop the libc++ headers from being extracted in the first place, rather than trying to filter results after the fact. If CodeQL never indexes those headers, no path can terminate in them and the FP cannot be produced.
Changes
In both CodeQL workflows, add
env:to theInitialize CodeQLstep (so the variables are set during extraction) configuring the C++ extractor to:Concretely, set on the
Initialize CodeQLstep in both.github/workflows/codeql-push.ymland.github/workflows/codeql-daily.yml:Do not remove the existing
paths-ignorein.github/codeql/codeql-config.yml— leave it as a backstop.Files to change
.github/workflows/codeql-push.yml— add theenv:block to theInitialize CodeQLstep..github/workflows/codeql-daily.yml— add the sameenv:block to theInitialize CodeQLstep.Out of scope
codeql-config.yml.query-filtersor exclude thecpp/new-free-mismatchquery.Validation
The PR's
CodeQL/pushworkflow should run successfully and complete a CodeQL analysis. The actual FP suppression of alert 1881 can only be confirmed once the daily run executes againstmain, so a green CI run on this PR is sufficient.The following is the prior conversation context from the user's chat exploration (may be truncated):
User: this ones a fucker weve been trying to get rid of it one way or another
latest attempt was d7bc39f but that has made no difference
Assistant: Let me try to read the alert details and check whether the alert's primary location is actually inside the libc++ headers (because
paths-ignorefilters by primary location only).Assistant: I can't read the alert metadata through the API directly (
/code-scanning/alerts/{n}isn't exposed to me), but looking at d7bc39f and the commit message ("cpp/new-free-mismatchin<vector>") I'm fairly sure why your fix didn't move the needle. A few things stacked against you:Why
paths-ignorealmost certainly isn't going to kill 1881paths-ignoreis matched against an alert's primary location only. Forcpp/new-free-mismatchthe primary location is the allocation site (thenew/new[]), not wheredelete[]is called. If anywhere in the flow CodeQL has rooted the allocation in an Envoy.cc/.h(very likely for a templatedstd::vectorinstantiation), the primary location is in Envoy, not ininclude/c++/v1/vector, and your glob never matches. The<vector>you see in the alert UI is just the sink in the path, which is what makes it look like the alert lives in libc++.For compiled languages,
paths/paths-ignoreare post-filters with known soft spots around system/third-party headers. GitHub's own docs and the CodeQL C/C++ team have repeatedly stated this filter does not reliably suppress results that touch system/standar...This pull request was created from Copilot chat.