Skip to content

Commit cab005d

Browse files
Pigbibicodex
andauthored
ci/security/test: automated audit fixes for QuantRuntimeSettings (#140)
* fix: harden runtime settings audit gate Co-Authored-By: Codex <noreply@openai.com> * test: avoid gate fixture false positive Co-Authored-By: Codex <noreply@openai.com> * chore: sync internal dependency matrix Co-Authored-By: Codex <noreply@openai.com> --------- Co-authored-by: Codex <noreply@openai.com>
1 parent ad6117a commit cab005d

3 files changed

Lines changed: 47 additions & 2 deletions

File tree

.github/workflows/validate.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ jobs:
1818
- uses: actions/setup-python@v6
1919
with:
2020
python-version: "3.12"
21+
- name: Install Python packaging tools
22+
run: |
23+
set -euo pipefail
24+
python3 -m pip install --upgrade pip
25+
python3 -m pip install build -e ./python
26+
- name: Verify Python dependencies
27+
run: python3 -m pip check
2128
- name: Check whitespace
2229
run: |
2330
set -euo pipefail
@@ -33,6 +40,8 @@ jobs:
3340
run: python3 python/scripts/runtime_settings.py validate
3441
- name: Run Python unit tests
3542
run: python3 -m unittest discover -s python/tests -v
43+
- name: Build Python package
44+
run: python3 -m build ./python
3645
- name: Checkout internal dependency consumer repos
3746
env:
3847
GH_TOKEN: ${{ github.token }}

python/scripts/gate_codex_app_review.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def compile_patterns(policy: dict[str, Any]) -> list[re.Pattern[str]]:
100100
# ─── static guard ────────────────────────────────────────────────────────────
101101

102102
_SENSITIVE = re.compile(
103-
r'(?:api[_\s]?key|secret|password|token|credential|private[_\s]?key)\s*[:=]\s*["\']'
103+
r'(?P<field>api[_\s]?key|secret|password|token|credential|private[_\s]?key)\s*[:=]\s*["\']'
104104
r'(?!\$\{\{|{{|example|placeholder|test|your[-_\s]|xxx|TODO|CHANGEME)[^"\']{12,}["\']',
105105
re.IGNORECASE,
106106
)
@@ -125,7 +125,7 @@ def scan_diff(diff_text: str, path_patterns: list[re.Pattern[str]]) -> list[str]
125125
continue
126126
m = _SENSITIVE.search(line[1:])
127127
if m:
128-
violations.append(f"**Hardcoded secret** in `{current}`: `{m.group(0)[:100]}`")
128+
violations.append(f"**Hardcoded secret** in `{current}`: `{m.group('field')}=<redacted>`")
129129
return list(dict.fromkeys(violations))
130130

131131

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from __future__ import annotations
2+
3+
import importlib.util
4+
import sys
5+
import unittest
6+
from pathlib import Path
7+
8+
9+
ROOT = Path(__file__).resolve().parents[2]
10+
MODULE_PATH = ROOT / "python" / "scripts" / "gate_codex_app_review.py"
11+
SPEC = importlib.util.spec_from_file_location("gate_codex_app_review", MODULE_PATH)
12+
gate_codex_app_review = importlib.util.module_from_spec(SPEC)
13+
assert SPEC.loader is not None
14+
sys.modules[SPEC.name] = gate_codex_app_review
15+
SPEC.loader.exec_module(gate_codex_app_review)
16+
17+
18+
class GateCodexAppReviewTest(unittest.TestCase):
19+
def test_scan_diff_redacts_secret_values(self):
20+
diff = "\n".join(
21+
[
22+
"diff --git a/example.py b/example.py",
23+
"+++ b/example.py",
24+
'+api_key = "sk-' 'live-12345678901234567890"',
25+
]
26+
)
27+
28+
violations = gate_codex_app_review.scan_diff(diff, [])
29+
30+
self.assertEqual(len(violations), 1)
31+
self.assertIn("api_key=<redacted>", violations[0])
32+
self.assertNotIn("sk-live-12345678901234567890", violations[0])
33+
34+
35+
if __name__ == "__main__":
36+
unittest.main()

0 commit comments

Comments
 (0)