feat(sast): the CRA C rules also run on C++ (#373) #391

Merged
sharang merged 1 commits from feat/cpp-rules into main 2026-09-25 11:01:43 +00:00
Owner

Closes #373.

Our CRA rules for C were languages: [c], so semgrep never applied them to C++ sources (.cpp, .cc, .hpp), and C++ application code only got cppcheck. They now run on both.

Changes

  • Rule pack (compliance-agent/rules/cra_semgrep.yaml):
    • The six C rules are languages: [c, cpp]: unbounded string functions, scanf("%s"), non-literal format strings, hard-coded credentials, broken hash/cipher, rand().
    • They also catch the std:: spellings C++ uses: std::sprintf, std::printf(fmt), std::snprintf and so on.
    • Tried with semgrep 1.154 on a C++ sample with one line per rule, the std:: forms and a std::string credential. Every planted line fires; std::printf("%s\n", …), snprintf and std::string::append stay quiet.
  • Control map: the four semgrep bindings with C rules (cra-ai-8, 13, 16, 20) now list cpp, so a C++ target counts as checked for them on the CRA status.
  • Guard against drift: a new test reads the rule pack and fails if a control-map binding claims fewer languages than its rules run on.
  • Nightly fixture: c-sensor-node gains Core/Src/cli.cpp, a small C++ service console with three planted flaws (a std::string credential, std::sprintf, a non-literal std::printf) and one clean call.
    • Its baseline adds exactly those three semgrep findings.
    • cppcheck 2.10, the agent image's Debian bookworm version, run with the agent's flags, finds nothing new in cli.cpp and still exactly the three baseline findings in sensors.c.
    • The Makefile is unchanged, so the SBOM baseline stays the same.

Checked

  • cargo fmt --all --check.
  • clippy with the CI flags for compliance-agent.
  • Tests: agent semgrep tests, including the new drift check; control-map (C++ counts for memory safety).

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p

Closes #373. Our CRA rules for C were `languages: [c]`, so semgrep never applied them to C++ sources (`.cpp`, `.cc`, `.hpp`), and C++ application code only got cppcheck. They now run on both. ## Changes - **Rule pack** (`compliance-agent/rules/cra_semgrep.yaml`): - The six C rules are `languages: [c, cpp]`: unbounded string functions, `scanf("%s")`, non-literal format strings, hard-coded credentials, broken hash/cipher, `rand()`. - They also catch the `std::` spellings C++ uses: `std::sprintf`, `std::printf(fmt)`, `std::snprintf` and so on. - Tried with semgrep 1.154 on a C++ sample with one line per rule, the `std::` forms and a `std::string` credential. Every planted line fires; `std::printf("%s\n", …)`, `snprintf` and `std::string::append` stay quiet. - **Control map:** the four semgrep bindings with C rules (cra-ai-8, 13, 16, 20) now list `cpp`, so a C++ target counts as checked for them on the CRA status. - **Guard against drift:** a new test reads the rule pack and fails if a control-map binding claims fewer languages than its rules run on. - **Nightly fixture:** `c-sensor-node` gains `Core/Src/cli.cpp`, a small C++ service console with three planted flaws (a `std::string` credential, `std::sprintf`, a non-literal `std::printf`) and one clean call. - Its baseline adds exactly those three semgrep findings. - cppcheck 2.10, the agent image's Debian bookworm version, run with the agent's flags, finds nothing new in `cli.cpp` and still exactly the three baseline findings in `sensors.c`. - The Makefile is unchanged, so the SBOM baseline stays the same. ## Checked - `cargo fmt --all --check`. - clippy with the CI flags for compliance-agent. - Tests: agent semgrep tests, including the new drift check; control-map (C++ counts for memory safety). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang added 1 commit 2026-09-25 10:46:26 +00:00
feat(sast): the CRA C rules also run on C++ (#373)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 7m42s
2d7ab72136
The C rules were semgrep `languages: [c]`, so C++ application code only
got cppcheck. They now run on C and C++, including the std:: spellings;
the control map says so, a test keeps the map and the rule pack in
step, and the nightly C fixture gains a C++ module with three planted
flaws.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang merged commit 9a0d690036 into main 2026-09-25 11:01:43 +00:00
Sign in to join this conversation.