feat(sast): hard-coded credentials in #define macros (#374) #392

Merged
sharang merged 1 commits from feat/define-credentials into main 2026-09-25 11:16:33 +00:00
Owner

Closes #374. Stacked on #391 (C rules on C++); it merges after #391.

The hard-coded credential rule for C only matched variable initialisers (const char *password = "..."). The usual embedded style, a macro in a config header (#define WIFI_PASS "..."), went unnoticed, so most ESP-IDF and STM32 projects gave no hits. semgrep's structural C patterns do not see preprocessor lines (tried: no match, no error).

Changes (cra-ai-8-c-hardcoded-credential, same rule id)

  • #define lines: a pattern-regex alternative matches #define NAME "value" in C and C++ sources and headers. Its named groups feed the same $NAME / $VALUE checks as the variable patterns. Keeping one rule id means the control map, the triage and the baselines need no change.
  • Credential names: PASS now counts on its own as well (WIFI_PASS, MQTT_PASS), besides passw/pwd/secret/api_key/token/psk/credential.
  • Placeholders are ignored, for variables too: changeme, password, secret, admin, xxx…, YOUR_…, <…> and ***. Values under six characters are still not reported.

Tried with semgrep 1.154:

  • Flagged: WIFI_PASS "Zebra-4711-x", PSK "a8f5…", DEVICE_PWD_DEFAULT "admin123" (in .h and .hpp), and wifi_password = "hunter2hunter2".
  • Not flagged: WIFI_SSID, MQTT_PASSWORD "changeme", API_KEY "YOUR_API_KEY", TOKEN "", SECRET_LEN 32, mqtt_passwd[] = "changeme", compass_heading = "north-east".

Nightly

c-sensor-node gains Core/Inc/net_config.h: MQTT_PASSWORD "sensor-Mq77!" is reported (baseline net_config.h:7), and the placeholder OTA_TOKEN "changeme" is not. The fixture's existing findings are unchanged.

Checked

semgrep --validate on the rule pack; agent semgrep tests, including the control-map language check.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p

Closes #374. Stacked on #391 (C rules on C++); it merges after #391. The hard-coded credential rule for C only matched variable initialisers (`const char *password = "..."`). The usual embedded style, a macro in a config header (`#define WIFI_PASS "..."`), went unnoticed, so most ESP-IDF and STM32 projects gave no hits. semgrep's structural C patterns do not see preprocessor lines (tried: no match, no error). ## Changes (`cra-ai-8-c-hardcoded-credential`, same rule id) - **`#define` lines:** a `pattern-regex` alternative matches `#define NAME "value"` in C and C++ sources and headers. Its named groups feed the same `$NAME` / `$VALUE` checks as the variable patterns. Keeping one rule id means the control map, the triage and the baselines need no change. - **Credential names:** `PASS` now counts on its own as well (`WIFI_PASS`, `MQTT_PASS`), besides passw/pwd/secret/api_key/token/psk/credential. - **Placeholders are ignored,** for variables too: `changeme`, `password`, `secret`, `admin`, `xxx…`, `YOUR_…`, `<…>` and `***`. Values under six characters are still not reported. Tried with semgrep 1.154: - **Flagged:** `WIFI_PASS "Zebra-4711-x"`, `PSK "a8f5…"`, `DEVICE_PWD_DEFAULT "admin123"` (in `.h` and `.hpp`), and `wifi_password = "hunter2hunter2"`. - **Not flagged:** `WIFI_SSID`, `MQTT_PASSWORD "changeme"`, `API_KEY "YOUR_API_KEY"`, `TOKEN ""`, `SECRET_LEN 32`, `mqtt_passwd[] = "changeme"`, `compass_heading = "north-east"`. ## Nightly `c-sensor-node` gains `Core/Inc/net_config.h`: `MQTT_PASSWORD "sensor-Mq77!"` is reported (baseline `net_config.h:7`), and the placeholder `OTA_TOKEN "changeme"` is not. The fixture's existing findings are unchanged. ## Checked `semgrep --validate` on the rule pack; agent semgrep tests, including the control-map language check. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang changed target branch from feat/cpp-rules to main 2026-09-25 11:01:50 +00:00
sharang added 1 commit 2026-09-25 11:01:50 +00:00
feat(sast): hard-coded credentials in #define macros (#374)
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 8m33s
5a5d7d11ee
The C credential rule only matched variable initialisers, so the usual
`#define WIFI_PASS "..."` in a config header went unnoticed. A regex
alternative now covers #define lines in C and C++, PASS counts as a
credential name, and placeholders (changeme, YOUR_..., xxx) are
ignored. The nightly C fixture gains a config header with one real and
one placeholder credential.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang force-pushed feat/define-credentials from 0305b8cf7e to 5a5d7d11ee 2026-09-25 11:01:51 +00:00 Compare
sharang merged commit aee2f5b9eb into main 2026-09-25 11:16:33 +00:00
Sign in to join this conversation.