fix(codeql): move clang bundle to $RUNNER_TEMP to eliminate libc++ false positives#44804
Closed
fix(codeql): move clang bundle to $RUNNER_TEMP to eliminate libc++ false positives#44804
Conversation
…tives (alert #1881) Agent-Logs-Url: https://github.com/envoyproxy/envoy/sessions/d959fb91-3782-4d07-af80-e2dfbf798f50 Co-authored-by: phlax <454682+phlax@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix code scanning alert 1881 for cpp/new-free-mismatch
fix(codeql): move clang bundle to $RUNNER_TEMP to eliminate libc++ false positives
May 1, 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.
Code scanning alert #1881 (
cpp/new-free-mismatch) kept reappearing atbin/clang18.1.8/include/c++/v1/vectordespite five previous suppression attempts — because the clang+llvm bundle was unpacked inside$GITHUB_WORKSPACE, causing CodeQL to treat bundled libc++ headers as project source rather than system headers.Root cause
The CodeQL C++ extractor classifies headers as system headers only when they live outside the source root. With the bundle at
bin/clang18.1.8/(inside$GITHUB_WORKSPACE), everypaths-ignoreglob,CODEQL_EXTRACTOR_CPP_OPTION_EXCLUDE_HEADER_PATTERNS, andCODEQL_EXTRACTOR_CPP_WIP_IGNORE_SYSTEM_HEADERStrick was fighting a losing battle — CodeQL never agreed those headers were system headers to begin with.Changes
Both CodeQL workflows (
codeql-push.yml,codeql-daily.yml):${RUNNER_TEMP}/clang18.1.8instead ofbin/clang18.1.8BAZEL_LLVM_PATHaccordinglyCODEQL_EXTRACTOR_CPP_OPTION_EXCLUDE_HEADER_PATTERNSandCODEQL_EXTRACTOR_CPP_WIP_IGNORE_SYSTEM_HEADERSenv varsconfig-file:references to the deleted configmkdirsite explaining the$RUNNER_TEMPconstraint (with alert reference) so no one "tidies" it back into the checkout.github/codeql/codeql-config.yml: deleted — thepaths-ignore: '**/include/c++/v1/**'entry it contained is redundant once the bundle is outside the source root; a stub config file is more confusing than nothingNo CodeQL queries are weakened —
cpp/new-free-mismatchand all other checks remain fully active against Envoy source code. This removes a misclassification, not a check.Supersedes workarounds from #44609, #44767, #44768.
Original prompt
Background
Code scanning alert #1881 (
cpp/new-free-mismatch, severity High) keeps reappearing with primary location:There have been five previous attempts to silence/work-around this, none of which fixed the root cause:
paths-ignore: '**/include/c++/v1/**'in.github/codeql/codeql-config.ymlpaths-ignorehas known weak semantics for compiled C/C++ — it filters which TUs are extracted as roots, not which files alerts can land in. Headers pulled in transitively from Envoy TUs still produce alerts.CODEQL_EXTRACTOR_CPP_OPTION_EXCLUDE_HEADER_PATTERNS=bin/clang.*/.*CODEQL_EXTRACTOR_CPP_WIP_IGNORE_SYSTEM_HEADERS=trueRoot cause
Both
.github/workflows/codeql-push.ymland.github/workflows/codeql-daily.ymlunpack the prebuilt clang+llvm 18.1.8 bundle into the checkout directory:bin/clang18.1.8/lives inside$GITHUB_WORKSPACE(the checkout root). The CodeQL C++ extractor classifies a header as a system header — and excludes alerts in it by default — based on whether it lives outside the source root. Anything under$GITHUB_WORKSPACEis treated as project source. That is why every "ignore libc++" attempt has been a losing battle: from CodeQL's point of view,bin/clang18.1.8/include/c++/v1/vectoris just as much "Envoy source" assource/common/http/conn_manager_impl.cc.Started when CodeQL began successfully extracting TUs that pull in
<vector>(i.e. when the CodeQL build was fixed). Before then extraction was partial and these TUs were never reached.Fix
Unpack the clang bundle outside
$GITHUB_WORKSPACE, in$RUNNER_TEMP. CodeQL will then treat the bundled libc++ headers as system headers, exactly as it would/usr/include/c++/13/vectoron a normal Linux build. No config knobs, no undocumented env vars, nopaths-ignoreglob required. Thecpp/new-free-mismatchquery (and all other queries) remain fully active across Envoy's own code.Required changes
1.
.github/workflows/codeql-push.ymlInstall depsstep, replacemkdir -p bin/clang18.1.8/cd bin/clang18.1.8withmkdir -p "${RUNNER_TEMP}/clang18.1.8"/cd "${RUNNER_TEMP}/clang18.1.8".Buildstep, change--repo_env=BAZEL_LLVM_PATH="$(realpath bin/clang18.1.8)"to--repo_env=BAZEL_LLVM_PATH="${RUNNER_TEMP}/clang18.1.8".env:block on theInitialize CodeQLstep that setsCODEQL_EXTRACTOR_CPP_OPTION_EXCLUDE_HEADER_PATTERNSandCODEQL_EXTRACTOR_CPP_WIP_IGNORE_SYSTEM_HEADERS. They are no longer needed.mkdir/tarlines explaining why the bundle must live outside$GITHUB_WORKSPACE(so a future contributor doesn't "tidy" it back into the checkout). Reference alert ssl: update BoringSSL to ae9f0616 (3202). #1881.Clean Artifactsstep'sgit clean -xdfpreviously also removed the in-treebin/clang18.1.8/. Confirm this is still fine (it is — the bundle is now in$RUNNER_TEMP, which the runner cleans up itself).2.
.github/workflows/codeql-daily.ymlApply exactly the same three edits (mkdir/cd path, BAZEL_LLVM_PATH, drop the env vars).
3.
.github/codeql/codeql-config.ymlThe
paths-ignore: '**/include/c++/v1/**'entry is no longer needed. Either:config-file: ./.github/codeql/codeql-config.ymlline from both workflows'Initialize CodeQLstep; orname:and a comment block explaining that with the toolchain in$RUNNER_TEMPno exclusions are required, and leaving the file in place avoids workflow churn if exclusions are ever needed again.Pick whichever is cleaner — I lean towards removing both the file and the
config-file:references since there is now nothing to configure and a stub config file is more confusing than helpful.4. Inline comments
Update the comment block currently in
codeql-config.yml(which describes the old workaround) so its replacement — wherever it ends up — explains the actual constraint:This pull request was created from Copilot chat.