codeveto 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codeveto/__init__.py +3 -0
- codeveto/__main__.py +8 -0
- codeveto/ai/__init__.py +19 -0
- codeveto/ai/harness.py +303 -0
- codeveto/ai/packets.py +855 -0
- codeveto/ai/policy.py +222 -0
- codeveto/ai/prompt.py +101 -0
- codeveto/ai/providers/__init__.py +178 -0
- codeveto/ai/providers/claude.py +247 -0
- codeveto/ai/providers/openai_compat.py +246 -0
- codeveto/ai/runner.py +293 -0
- codeveto/ai/verify.py +324 -0
- codeveto/anchor.py +211 -0
- codeveto/cli.py +247 -0
- codeveto/cli_explain.py +49 -0
- codeveto/cli_hook.py +31 -0
- codeveto/cli_init.py +254 -0
- codeveto/cli_mcp.py +29 -0
- codeveto/cli_packets.py +35 -0
- codeveto/cli_publish.py +29 -0
- codeveto/cli_review.py +362 -0
- codeveto/cli_rules.py +78 -0
- codeveto/cli_verify.py +47 -0
- codeveto/config.py +1229 -0
- codeveto/data/README.md +16 -0
- codeveto/data/ai-wire.schema.json +53 -0
- codeveto/data/prompts/system.md +57 -0
- codeveto/data/report-v1.schema.json +268 -0
- codeveto/data/templates/forgejo-codeveto.yml +104 -0
- codeveto/data/templates/github-codeveto.yml +18 -0
- codeveto/embedded.py +311 -0
- codeveto/engine.py +1570 -0
- codeveto/git.py +1549 -0
- codeveto/globs.py +348 -0
- codeveto/integrations/__init__.py +1 -0
- codeveto/integrations/hooks.py +327 -0
- codeveto/integrations/mcp.py +770 -0
- codeveto/integrations/mcp_ai.py +77 -0
- codeveto/integrations/prepush.py +222 -0
- codeveto/jsonsafe.py +60 -0
- codeveto/languages.py +539 -0
- codeveto/lexers.py +2560 -0
- codeveto/model.py +372 -0
- codeveto/publish/__init__.py +28 -0
- codeveto/publish/action.py +330 -0
- codeveto/publish/common.py +84 -0
- codeveto/publish/diff.py +208 -0
- codeveto/publish/event.py +241 -0
- codeveto/publish/forgejo.py +184 -0
- codeveto/publish/github.py +380 -0
- codeveto/publish/http.py +263 -0
- codeveto/publish/pull.py +218 -0
- codeveto/publish/untrusted.py +110 -0
- codeveto/py.typed +0 -0
- codeveto/redact.py +113 -0
- codeveto/render/__init__.py +64 -0
- codeveto/render/agent.py +43 -0
- codeveto/render/github.py +101 -0
- codeveto/render/json.py +23 -0
- codeveto/render/markdown.py +208 -0
- codeveto/render/safe.py +249 -0
- codeveto/render/sarif.py +217 -0
- codeveto/render/text.py +210 -0
- codeveto/report.py +252 -0
- codeveto/rules/__init__.py +84 -0
- codeveto/rules/agent.py +2972 -0
- codeveto/rules/base.py +1026 -0
- codeveto/rules/ci.py +1708 -0
- codeveto/rules/config.py +493 -0
- codeveto/rules/deps.py +1693 -0
- codeveto/rules/docker.py +479 -0
- codeveto/rules/examples/__init__.py +148 -0
- codeveto/rules/examples/agent.py +839 -0
- codeveto/rules/examples/ci.py +1046 -0
- codeveto/rules/examples/config.py +191 -0
- codeveto/rules/examples/deps.py +369 -0
- codeveto/rules/examples/docker.py +157 -0
- codeveto/rules/examples/go.py +241 -0
- codeveto/rules/examples/hygiene.py +466 -0
- codeveto/rules/examples/js.py +462 -0
- codeveto/rules/examples/python.py +595 -0
- codeveto/rules/examples/rust.py +268 -0
- codeveto/rules/examples/secrets.py +561 -0
- codeveto/rules/examples/security.py +608 -0
- codeveto/rules/examples/shell.py +174 -0
- codeveto/rules/examples/sql.py +194 -0
- codeveto/rules/examples/tests.py +497 -0
- codeveto/rules/go.py +328 -0
- codeveto/rules/hygiene.py +1094 -0
- codeveto/rules/js.py +768 -0
- codeveto/rules/python.py +1642 -0
- codeveto/rules/rust.py +209 -0
- codeveto/rules/secrets.py +1335 -0
- codeveto/rules/security.py +3680 -0
- codeveto/rules/shell.py +867 -0
- codeveto/rules/sql.py +629 -0
- codeveto/rules/tests.py +1404 -0
- codeveto/schema.py +384 -0
- codeveto/statements.py +607 -0
- codeveto/worktree.py +1176 -0
- codeveto/yamlish.py +1179 -0
- codeveto-0.1.0.dist-info/METADATA +253 -0
- codeveto-0.1.0.dist-info/RECORD +106 -0
- codeveto-0.1.0.dist-info/WHEEL +4 -0
- codeveto-0.1.0.dist-info/entry_points.txt +2 -0
- codeveto-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
"""Examples for the secrets pack.
|
|
2
|
+
|
|
3
|
+
No credential appears here literally: every token is assembled at import time
|
|
4
|
+
from a prefix and deterministic pseudo-random material (:func:`material`), so
|
|
5
|
+
the source holds nothing a scanner could mistake for a real secret, and none
|
|
6
|
+
of the values is real.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import base64
|
|
12
|
+
import hashlib
|
|
13
|
+
import json
|
|
14
|
+
import textwrap
|
|
15
|
+
import zlib
|
|
16
|
+
|
|
17
|
+
from codeveto.rules.base import bad, good
|
|
18
|
+
from codeveto.rules.secrets import base62
|
|
19
|
+
|
|
20
|
+
B62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
|
21
|
+
B64 = B62 + "+/"
|
|
22
|
+
URLSAFE = B62 + "-_"
|
|
23
|
+
HEX = "0123456789abcdef"
|
|
24
|
+
UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def material(seed: str, length: int, alphabet: str = B62) -> str:
|
|
28
|
+
"""``length`` deterministic pseudo-random characters of ``alphabet`` for ``seed``."""
|
|
29
|
+
out: list[str] = []
|
|
30
|
+
counter = 0
|
|
31
|
+
while len(out) < length:
|
|
32
|
+
block = hashlib.sha256(f"{seed}/{counter}".encode()).digest()
|
|
33
|
+
out.extend(alphabet[b % len(alphabet)] for b in block)
|
|
34
|
+
counter += 1
|
|
35
|
+
return "".join(out[:length])
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def join(*parts: str) -> str:
|
|
39
|
+
return "".join(parts)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def github_classic(seed: str, prefix: str = "ghp") -> str:
|
|
43
|
+
body = material(seed, 30)
|
|
44
|
+
return join(prefix, "_", body, base62(zlib.crc32(body.encode()), 6))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def b64url(data: dict[str, object]) -> str:
|
|
48
|
+
return base64.urlsafe_b64encode(json.dumps(data).encode()).decode().rstrip("=")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def jwt(seed: str, header: dict[str, object], payload: dict[str, object]) -> str:
|
|
52
|
+
return ".".join((b64url(header), b64url(payload), material(seed, 43, URLSAFE)))
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def pem_body(seed: str, size: int = 900) -> list[str]:
|
|
56
|
+
raw = b"\x30\x82\x04\xa4\x02\x01\x00" + hashlib.shake_256(seed.encode()).digest(size)
|
|
57
|
+
return textwrap.wrap(base64.b64encode(raw).decode(), 64)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def pem(label: str, seed: str) -> list[str]:
|
|
61
|
+
dashes = "-" * 5
|
|
62
|
+
return [
|
|
63
|
+
join(dashes, "BEGIN ", label, dashes),
|
|
64
|
+
*pem_body(seed),
|
|
65
|
+
join(dashes, "END ", label, dashes),
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
DASHES = "-" * 5
|
|
70
|
+
BEGIN_RSA = join(DASHES, "BEGIN RSA ", "PRIVATE KEY", DASHES)
|
|
71
|
+
END_RSA = join(DASHES, "END RSA ", "PRIVATE KEY", DASHES)
|
|
72
|
+
BEGIN_PKCS8 = join(DASHES, "BEGIN ", "PRIVATE KEY", DASHES)
|
|
73
|
+
END_PKCS8 = join(DASHES, "END ", "PRIVATE KEY", DASHES)
|
|
74
|
+
|
|
75
|
+
AWS_ID = join("AKIA", material("aws-id", 16, UPPER))
|
|
76
|
+
AWS_TEMP_ID = join("ASIA", material("aws-temp-id", 16, UPPER))
|
|
77
|
+
AWS_ID_CANARY = join("AKIA", "IOSFODNN7", "EXAMPLE")
|
|
78
|
+
AWS_SECRET = material("aws-secret", 40, B64)
|
|
79
|
+
AWS_SECRET_2 = material("aws-secret-2", 40, B64)
|
|
80
|
+
AWS_SECRET_CANARY = join("wJalrXUtnFEMI/K7MDENG/", "bPxRfiCY", "EXAMPLEKEY")
|
|
81
|
+
|
|
82
|
+
GHP = github_classic("ghp")
|
|
83
|
+
GHO = github_classic("gho", "gho")
|
|
84
|
+
GHP_BAD_CHECKSUM = join("ghp_", material("ghp-wrong", 36))
|
|
85
|
+
GITHUB_PAT = join("github_pat_", material("pat-a", 22), "_", material("pat-b", 59))
|
|
86
|
+
GHP_CANARY = join("ghp_", "16C7e42F292c6912", "E7710c838347Ae178B4a")
|
|
87
|
+
|
|
88
|
+
GLPAT = join("glpat-", material("glpat", 20, URLSAFE))
|
|
89
|
+
GLRT = join("glrt-", material("glrt", 20, URLSAFE))
|
|
90
|
+
|
|
91
|
+
XOXB = join("xoxb-", "2843910571", "-", "4417238390129", "-", material("xoxb", 24))
|
|
92
|
+
XOXP = join(
|
|
93
|
+
"xoxp-", "2843910571", "-", "2851024793", "-", "4417260155906", "-", material("xoxp", 32, HEX)
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
SLACK_HOOK = join(
|
|
97
|
+
"https://hooks.slack", ".com/services/T04B7K2QX9M/B05C8RL1W2Z/", material("hook", 24)
|
|
98
|
+
)
|
|
99
|
+
SLACK_WORKFLOW = join(
|
|
100
|
+
"https://hooks.slack",
|
|
101
|
+
".com/workflows/T04B7K2QX9M/A06D2HV9QKP/498877123456789012/",
|
|
102
|
+
material("workflow", 32),
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
STRIPE_SK = join("sk_", "live_", "51N", material("stripe-sk", 96))
|
|
106
|
+
STRIPE_RK = join("rk_", "live_", "51N", material("stripe-rk", 96))
|
|
107
|
+
STRIPE_TEST = join("sk_", "test_", "51N", material("stripe-test", 96))
|
|
108
|
+
STRIPE_PK = join("pk_", "live_", "51N", material("stripe-pk", 96))
|
|
109
|
+
STRIPE_CANARY = join("sk_", "live_", "4eC39HqLyjWD", "arjtT1zdp7dc")
|
|
110
|
+
|
|
111
|
+
GOOGLE = join("AIza", "Sy", material("google", 33, URLSAFE))
|
|
112
|
+
GOOGLE_FIREBASE = join("AIza", "Sy", material("firebase", 33, URLSAFE))
|
|
113
|
+
|
|
114
|
+
OPENAI = join("sk-", "proj-", material("openai", 156, URLSAFE))
|
|
115
|
+
OPENAI_LEGACY = join("sk-", material("oa-1", 20), "T3Blbk", "FJ", material("oa-2", 20))
|
|
116
|
+
|
|
117
|
+
ANTHROPIC = join("sk-", "ant-", "api03-", material("anthropic", 93, URLSAFE), "AA")
|
|
118
|
+
ANTHROPIC_ADMIN = join("sk-", "ant-", "admin01-", material("anthropic-admin", 93, URLSAFE), "AA")
|
|
119
|
+
|
|
120
|
+
NPM = join("npm_", material("npm", 36))
|
|
121
|
+
NPM_2 = join("npm_", material("npm-2", 36))
|
|
122
|
+
|
|
123
|
+
PYPI = join("pypi-", "AgEIcHlwaS5vcmc", material("pypi", 160, URLSAFE))
|
|
124
|
+
TESTPYPI = join("pypi-", "AgENdGVzdC5weXBpLm9yZw", material("testpypi", 160, URLSAFE))
|
|
125
|
+
|
|
126
|
+
JWT_HS = jwt(
|
|
127
|
+
"jwt-hs",
|
|
128
|
+
{"alg": "HS256", "typ": "JWT"},
|
|
129
|
+
{"sub": "svc-billing", "iat": 1767225600, "scope": "invoices:write"},
|
|
130
|
+
)
|
|
131
|
+
JWT_RS = jwt("jwt-rs", {"alg": "RS256", "kid": "k2"}, {"iss": "https://auth.acme.io", "sub": "42"})
|
|
132
|
+
NOT_JWT = ".".join(
|
|
133
|
+
("eyJ" + material("hdr", 20, URLSAFE), "eyJ" + material("pl", 20), material("sig", 43, URLSAFE))
|
|
134
|
+
)
|
|
135
|
+
JWT_CANARY = jwt(
|
|
136
|
+
"jwt-io",
|
|
137
|
+
{"alg": "HS256", "typ": "JWT"},
|
|
138
|
+
{"sub": "1234567890", "name": "John Doe", "iat": 1516239022},
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
PASSWORD = material("db-password", 24, B62 + "!#%&*+-.")
|
|
142
|
+
PASSWORD_2 = material("git-password", 20, B62)
|
|
143
|
+
DJANGO_KEY = material("django", 50, B62 + "!@#%^&*(-_=+)")
|
|
144
|
+
CLIENT_SECRET = join("GOCSPX-", material("oauth-client", 28, URLSAFE))
|
|
145
|
+
API_KEY = material("api-key", 32, B62)
|
|
146
|
+
UUID_TOKEN = "-".join(material(f"uuid-{n}", size, HEX) for n, size in enumerate((8, 4, 4, 4, 12)))
|
|
147
|
+
|
|
148
|
+
KEY_LINES = pem("RSA PRIVATE KEY", "rsa-key")
|
|
149
|
+
KEY_BLOCK = "\n".join(KEY_LINES)
|
|
150
|
+
PKCS8_ONE_LINE = "\\n".join(pem("PRIVATE KEY", "service-account")) + "\\n"
|
|
151
|
+
OPENSSH_LINES = pem("OPENSSH PRIVATE KEY", "openssh")
|
|
152
|
+
|
|
153
|
+
EXAMPLES = {
|
|
154
|
+
"secrets/private-key": [
|
|
155
|
+
bad(
|
|
156
|
+
"src/billing/signing.py",
|
|
157
|
+
f'SIGNING_KEY = """{BEGIN_RSA} # expect\n' + "\n".join(KEY_LINES[1:]) + '\n"""\n',
|
|
158
|
+
note="A PEM key pasted into a module: the hit spans the block, each body line redacted.",
|
|
159
|
+
),
|
|
160
|
+
bad(
|
|
161
|
+
"deploy/service-account.json",
|
|
162
|
+
"{\n"
|
|
163
|
+
' "type": "service_account",\n'
|
|
164
|
+
f' "private_key": "{PKCS8_ONE_LINE}",\n'
|
|
165
|
+
' "client_email": "ci@acme-prod.iam.gserviceaccount.com"\n'
|
|
166
|
+
"}\n",
|
|
167
|
+
expect=[("deploy/service-account.json", 3, "new")],
|
|
168
|
+
note="A service-account key on one line with \\n escapes.",
|
|
169
|
+
),
|
|
170
|
+
bad(
|
|
171
|
+
"ansible/group_vars/web.yml",
|
|
172
|
+
"deploy_user: deploy\n"
|
|
173
|
+
"deploy_ssh_key: |\n"
|
|
174
|
+
+ "".join(
|
|
175
|
+
f" {line}{' # expect' if i == 0 else ''}\n"
|
|
176
|
+
for i, line in enumerate(OPENSSH_LINES)
|
|
177
|
+
),
|
|
178
|
+
note="An OpenSSH key in a YAML block scalar.",
|
|
179
|
+
),
|
|
180
|
+
bad(
|
|
181
|
+
"src/billing/legacy.py",
|
|
182
|
+
"x = 1\n"
|
|
183
|
+
+ "".join(
|
|
184
|
+
f"# {line}{' # expect' if i == 0 else ''}\n" for i, line in enumerate(KEY_LINES)
|
|
185
|
+
),
|
|
186
|
+
note="A key commented out in Python is still in the history; each line is redacted.",
|
|
187
|
+
),
|
|
188
|
+
bad(
|
|
189
|
+
"src/deploy/key.js",
|
|
190
|
+
"".join(
|
|
191
|
+
f"// {line}{' // expect' if i == 0 else ''}\n"
|
|
192
|
+
for i, line in enumerate(OPENSSH_LINES)
|
|
193
|
+
)
|
|
194
|
+
+ "export const host = 'deploy.acme.io';\n",
|
|
195
|
+
note="A key in // line comments.",
|
|
196
|
+
),
|
|
197
|
+
bad(
|
|
198
|
+
"src/deploy/signer.ts",
|
|
199
|
+
"/*\n"
|
|
200
|
+
+ "".join(
|
|
201
|
+
f" * {line}{' // expect' if i == 0 else ''}\n" for i, line in enumerate(KEY_LINES)
|
|
202
|
+
)
|
|
203
|
+
+ " */\nexport const signer = 'ops';\n",
|
|
204
|
+
note="A key in a /* */ block comment with * leaders.",
|
|
205
|
+
),
|
|
206
|
+
good(
|
|
207
|
+
"src/crypto/pem.py",
|
|
208
|
+
f'PRIVATE_HEADER = "{BEGIN_PKCS8}"\n'
|
|
209
|
+
f'PRIVATE_FOOTER = "{END_PKCS8}"\n'
|
|
210
|
+
"\n\ndef is_private(text: str) -> bool:\n"
|
|
211
|
+
" return text.lstrip().startswith(PRIVATE_HEADER)\n",
|
|
212
|
+
note="Code that names the markers holds no key material.",
|
|
213
|
+
),
|
|
214
|
+
good(
|
|
215
|
+
"docs/deploy.md",
|
|
216
|
+
f"Paste the key into the secret store:\n\n```\n{BEGIN_RSA}\n...\n{END_RSA}\n```\n",
|
|
217
|
+
note="A documentation placeholder body is not a key.",
|
|
218
|
+
),
|
|
219
|
+
good(
|
|
220
|
+
"src/crypto/detect.py",
|
|
221
|
+
f"# A PEM key starts with {BEGIN_RSA} and ends with {END_RSA}.\n"
|
|
222
|
+
"def is_pem(text):\n return text.startswith('-----')\n",
|
|
223
|
+
note="A comment that only names the markers.",
|
|
224
|
+
),
|
|
225
|
+
good(
|
|
226
|
+
"src/deploy/key.js",
|
|
227
|
+
f"// {BEGIN_RSA}\n// <paste the deploy key here>\n// {END_RSA}\n"
|
|
228
|
+
"export const host = 'deploy.acme.io';\n",
|
|
229
|
+
note="A commented key header with a placeholder body.",
|
|
230
|
+
),
|
|
231
|
+
good(
|
|
232
|
+
"certs/ca.pem",
|
|
233
|
+
"\n".join(
|
|
234
|
+
[
|
|
235
|
+
join(DASHES, "BEGIN CERTIFICATE", DASHES),
|
|
236
|
+
*pem_body("ca"),
|
|
237
|
+
join(DASHES, "END CERTIFICATE", DASHES),
|
|
238
|
+
]
|
|
239
|
+
)
|
|
240
|
+
+ "\n",
|
|
241
|
+
note="A certificate is public.",
|
|
242
|
+
),
|
|
243
|
+
],
|
|
244
|
+
"secrets/aws-access-key": [
|
|
245
|
+
bad("src/storage/settings.py", f'AWS_ACCESS_KEY_ID = "{AWS_ID}" # expect\n'),
|
|
246
|
+
bad(
|
|
247
|
+
"infra/main.tf",
|
|
248
|
+
'provider "aws" {\n'
|
|
249
|
+
' region = "eu-central-1"\n'
|
|
250
|
+
f' access_key = "{AWS_TEMP_ID}" # expect\n'
|
|
251
|
+
"}\n",
|
|
252
|
+
note="Temporary (ASIA) key IDs are credentials too.",
|
|
253
|
+
),
|
|
254
|
+
bad(
|
|
255
|
+
"docs/aws.md",
|
|
256
|
+
f"Set `AWS_ACCESS_KEY_ID`, for example `{AWS_ID_CANARY}`. <!-- expect -->\n",
|
|
257
|
+
note="AWS's documentation key ID is a canary: reported as a note only.",
|
|
258
|
+
),
|
|
259
|
+
good(
|
|
260
|
+
"src/storage/settings.py",
|
|
261
|
+
'AWS_ACCESS_KEY_ID = os.environ["AWS_ACCESS_KEY_ID"]\n'
|
|
262
|
+
'PLACEHOLDER_ID = "AKIA' + "X" * 16 + '"\n',
|
|
263
|
+
),
|
|
264
|
+
good(
|
|
265
|
+
"src/storage/ids.py",
|
|
266
|
+
f'DIGEST = "{material("digest", 8, UPPER)}{AWS_ID}"\n',
|
|
267
|
+
note="Inside a longer token the prefix is not a key ID.",
|
|
268
|
+
),
|
|
269
|
+
],
|
|
270
|
+
"secrets/aws-secret-key": [
|
|
271
|
+
bad("src/storage/settings.py", f'AWS_SECRET_ACCESS_KEY = "{AWS_SECRET}" # expect\n'),
|
|
272
|
+
bad(
|
|
273
|
+
"deploy/backup.yaml",
|
|
274
|
+
f"s3:\n accessKeyId: !ref backup-id\n secretAccessKey: {AWS_SECRET_2} # expect\n",
|
|
275
|
+
),
|
|
276
|
+
bad(
|
|
277
|
+
"docs/aws.md",
|
|
278
|
+
f"aws_secret_access_key = {AWS_SECRET_CANARY} <!-- expect -->\n",
|
|
279
|
+
note="AWS's documentation secret is a canary: reported as a note only.",
|
|
280
|
+
),
|
|
281
|
+
good(
|
|
282
|
+
"src/storage/manifest.py",
|
|
283
|
+
f'BACKUP_ETAG = "{AWS_SECRET}"\n',
|
|
284
|
+
note="Without an AWS secret key name, 40 base64 characters are just data.",
|
|
285
|
+
),
|
|
286
|
+
good(
|
|
287
|
+
"src/storage/settings.py",
|
|
288
|
+
'AWS_SECRET_ACCESS_KEY = os.environ["AWS_SECRET_ACCESS_KEY"]\n'
|
|
289
|
+
f'aws_secret_key_sha1 = "{material("sha", 40, HEX)}"\n',
|
|
290
|
+
note="References, and 40 hex digits (a digest) are not secrets.",
|
|
291
|
+
),
|
|
292
|
+
],
|
|
293
|
+
"secrets/github-token": [
|
|
294
|
+
bad("scripts/release.py", f'GITHUB_TOKEN = "{GHP}" # expect\n'),
|
|
295
|
+
bad(
|
|
296
|
+
"src/github/client.ts",
|
|
297
|
+
f"const auth = new Octokit({{ auth: '{GHO}' }}); // expect\n",
|
|
298
|
+
note="OAuth tokens (gho_) share the classic format and checksum.",
|
|
299
|
+
),
|
|
300
|
+
bad(
|
|
301
|
+
"ci/mirror.sh",
|
|
302
|
+
f'git push "https://x:{GITHUB_PAT}@github.com/acme/mirror.git" # expect\n',
|
|
303
|
+
note="Fine-grained tokens are checked by shape.",
|
|
304
|
+
),
|
|
305
|
+
good(
|
|
306
|
+
"tests/test_tokens.py",
|
|
307
|
+
f'TOKEN = "{GHP_BAD_CHECKSUM}"\n',
|
|
308
|
+
note="Without a valid CRC32 checksum the value is a hand-made fake.",
|
|
309
|
+
),
|
|
310
|
+
good(
|
|
311
|
+
"README.md",
|
|
312
|
+
"Create a token (`ghp_" + "x" * 36 + "`) and export it as `GITHUB_TOKEN`.\n",
|
|
313
|
+
),
|
|
314
|
+
bad(
|
|
315
|
+
"docs/api.md",
|
|
316
|
+
f"curl -H 'Authorization: Bearer {GHP_CANARY}' https://api.github.com/user"
|
|
317
|
+
" <!-- expect -->\n",
|
|
318
|
+
note="GitHub's documentation token is a canary: reported as a note only.",
|
|
319
|
+
),
|
|
320
|
+
],
|
|
321
|
+
"secrets/gitlab-token": [
|
|
322
|
+
bad("scripts/sync.py", f'gitlab = Gitlab(url, private_token="{GLPAT}") # expect\n'),
|
|
323
|
+
bad("deploy/runner.yaml", f"runner:\n token: {GLRT} # expect\n"),
|
|
324
|
+
good("docs/gitlab.md", "Personal access tokens look like `glpat-" + "x" * 20 + "`.\n"),
|
|
325
|
+
good("ci/sync.sh", 'curl --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" "$API/projects"\n'),
|
|
326
|
+
],
|
|
327
|
+
"secrets/slack-token": [
|
|
328
|
+
bad("bot/config.py", f'SLACK_BOT_TOKEN = "{XOXB}" # expect\n'),
|
|
329
|
+
bad("bot/notify.js", f"const client = new WebClient('{XOXP}'); // expect\n"),
|
|
330
|
+
good(
|
|
331
|
+
"bot/config.py",
|
|
332
|
+
'SLACK_BOT_TOKEN = os.environ.get("SLACK_BOT_TOKEN", "xoxb-your-token")\n',
|
|
333
|
+
),
|
|
334
|
+
good(
|
|
335
|
+
"docs/slack.md",
|
|
336
|
+
"Bot tokens look like `xoxb-0000000000-0000000000-" + "X" * 24 + "`.\n",
|
|
337
|
+
),
|
|
338
|
+
],
|
|
339
|
+
"secrets/slack-webhook": [
|
|
340
|
+
bad("alerts/notify.py", f'WEBHOOK = "{SLACK_HOOK}" # expect\n'),
|
|
341
|
+
bad("alerts/workflow.yaml", f"trigger_url: {SLACK_WORKFLOW} # expect\n"),
|
|
342
|
+
good(
|
|
343
|
+
"docs/alerts.md",
|
|
344
|
+
"Webhook URLs look like https://hooks.slack.com/services/T00000000/B00000000/"
|
|
345
|
+
+ "X" * 24
|
|
346
|
+
+ "\n",
|
|
347
|
+
),
|
|
348
|
+
good("alerts/notify.py", 'WEBHOOK = os.environ["SLACK_WEBHOOK_URL"]\n'),
|
|
349
|
+
],
|
|
350
|
+
"secrets/stripe-live-key": [
|
|
351
|
+
bad("payments/client.py", f'stripe.api_key = "{STRIPE_SK}" # expect\n'),
|
|
352
|
+
bad(
|
|
353
|
+
"payments/refunds.rb",
|
|
354
|
+
f'Stripe.api_key = "{STRIPE_RK}" # expect\n',
|
|
355
|
+
note="Restricted live keys move money too.",
|
|
356
|
+
),
|
|
357
|
+
good(
|
|
358
|
+
"payments/client.py",
|
|
359
|
+
f'TEST_KEY = "{STRIPE_TEST}"\nPUBLISHABLE_KEY = "{STRIPE_PK}"\n',
|
|
360
|
+
note="Test keys and publishable keys are not live secrets.",
|
|
361
|
+
),
|
|
362
|
+
bad(
|
|
363
|
+
"docs/payments.md",
|
|
364
|
+
f"stripe.api_key = '{STRIPE_CANARY}' <!-- expect -->\n",
|
|
365
|
+
note="Stripe's documentation key body is a canary: reported as a note only.",
|
|
366
|
+
),
|
|
367
|
+
good("payments/client.py", 'stripe.api_key = os.environ["STRIPE_SECRET_KEY"]\n'),
|
|
368
|
+
],
|
|
369
|
+
"secrets/google-api-key": [
|
|
370
|
+
bad("services/geocode.py", f'MAPS_KEY = "{GOOGLE}" # expect\n'),
|
|
371
|
+
bad("deploy/geocoder.yaml", f"geocoder:\n api_key: {GOOGLE} # expect\n"),
|
|
372
|
+
good(
|
|
373
|
+
"web/src/firebase.ts",
|
|
374
|
+
"const firebaseConfig = {\n"
|
|
375
|
+
f' apiKey: "{GOOGLE_FIREBASE}",\n'
|
|
376
|
+
' authDomain: "acme-app.firebaseapp.com",\n'
|
|
377
|
+
"};\n",
|
|
378
|
+
note="Firebase web API keys are public identifiers by design.",
|
|
379
|
+
),
|
|
380
|
+
good("docs/maps.md", "Keys start with `AIza` followed by 35 characters.\n"),
|
|
381
|
+
],
|
|
382
|
+
"secrets/openai-key": [
|
|
383
|
+
bad("agent/llm.py", f'client = OpenAI(api_key="{OPENAI}") # expect\n'),
|
|
384
|
+
bad("agent/legacy.js", f"const key = '{OPENAI_LEGACY}'; // expect\n"),
|
|
385
|
+
good("agent/llm.py", 'client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])\n'),
|
|
386
|
+
good("docs/llm.md", "Project keys start with `sk-proj-`.\n"),
|
|
387
|
+
],
|
|
388
|
+
"secrets/anthropic-key": [
|
|
389
|
+
bad("agent/claude.py", f'client = Anthropic(api_key="{ANTHROPIC}") # expect\n'),
|
|
390
|
+
bad("agent/admin.ts", f"const adminKey = '{ANTHROPIC_ADMIN}'; // expect\n"),
|
|
391
|
+
good("agent/claude.py", "client = Anthropic() # reads ANTHROPIC_API_KEY\n"),
|
|
392
|
+
good(
|
|
393
|
+
"docs/agent.md",
|
|
394
|
+
"Keys look like `sk-ant-api03-" + "x" * 93 + "AA`.\n",
|
|
395
|
+
note="An obviously fake key body.",
|
|
396
|
+
),
|
|
397
|
+
],
|
|
398
|
+
"secrets/npm-token": [
|
|
399
|
+
bad("scripts/publish.sh", f'export NODE_AUTH_TOKEN="{NPM}" # expect\n'),
|
|
400
|
+
bad("ci/publish.yml", f"env:\n NPM_TOKEN: {NPM_2} # expect\n"),
|
|
401
|
+
good(".npmrc", "//registry.npmjs.org/:_authToken=${NPM_TOKEN}\n"),
|
|
402
|
+
good("docs/release.md", "Tokens look like `npm_" + "0123456789" * 3 + "abcdef`.\n"),
|
|
403
|
+
],
|
|
404
|
+
"secrets/pypi-token": [
|
|
405
|
+
bad("scripts/upload.sh", f"twine upload -u __token__ -p {PYPI} dist/* # expect\n"),
|
|
406
|
+
bad(
|
|
407
|
+
"scripts/upload_test.py",
|
|
408
|
+
f'TOKEN = "{TESTPYPI}" # expect\n',
|
|
409
|
+
note="TestPyPI tokens are credentials too.",
|
|
410
|
+
),
|
|
411
|
+
good("scripts/upload.sh", 'twine upload -u __token__ -p "$PYPI_TOKEN" dist/*\n'),
|
|
412
|
+
good("docs/release.md", "Tokens start with `pypi-AgEIcHlwaS5vcmc`.\n"),
|
|
413
|
+
],
|
|
414
|
+
"secrets/jwt": [
|
|
415
|
+
bad("src/jobs/billing.py", f'SERVICE_JWT = "{JWT_HS}" # expect\n'),
|
|
416
|
+
bad(
|
|
417
|
+
"deploy/gateway.yaml",
|
|
418
|
+
f"upstream:\n authorization: Bearer {JWT_RS} # expect\n",
|
|
419
|
+
),
|
|
420
|
+
bad(
|
|
421
|
+
"tests/test_auth.py",
|
|
422
|
+
f'SAMPLE = "{JWT_CANARY}" # expect\n',
|
|
423
|
+
note="The jwt.io sample is a canary: reported as a note only.",
|
|
424
|
+
),
|
|
425
|
+
good(
|
|
426
|
+
"src/auth/fixtures.py",
|
|
427
|
+
f'NOT_A_JWT = "{NOT_JWT}"\n',
|
|
428
|
+
note="A header that does not decode to JSON with an algorithm is not a JWT.",
|
|
429
|
+
),
|
|
430
|
+
good(
|
|
431
|
+
"src/auth/tokens.py",
|
|
432
|
+
'JWT_PREFIX = "eyJ"\ntoken = jwt.encode(claims, key, algorithm="RS256")\n',
|
|
433
|
+
),
|
|
434
|
+
],
|
|
435
|
+
"secrets/url-credentials": [
|
|
436
|
+
bad(
|
|
437
|
+
"src/db.py",
|
|
438
|
+
f'MONGO_URL = "mongodb+srv://app:{PASSWORD}@cluster0.x7k2q.mongodb.net/shop"'
|
|
439
|
+
" # expect\n",
|
|
440
|
+
),
|
|
441
|
+
bad(
|
|
442
|
+
"scripts/mirror.sh",
|
|
443
|
+
f"git clone https://deploy:{PASSWORD_2}@git.acme.io/platform/api.git # expect\n",
|
|
444
|
+
),
|
|
445
|
+
bad(
|
|
446
|
+
"deploy/compose.yml",
|
|
447
|
+
" environment:\n"
|
|
448
|
+
f" DATABASE_URL: postgres://app:{PASSWORD}@db:5432/app # expect\n",
|
|
449
|
+
note="On a service name only a strong password is reported.",
|
|
450
|
+
),
|
|
451
|
+
bad(
|
|
452
|
+
"tests/test_clone.py",
|
|
453
|
+
f'REMOTE = "https://ci:{PASSWORD_2}@git.acme.io/platform/api.git" # expect\n',
|
|
454
|
+
note="In test files a hit is only a warning.",
|
|
455
|
+
),
|
|
456
|
+
good(
|
|
457
|
+
"docker-compose.yml",
|
|
458
|
+
"services:\n"
|
|
459
|
+
" api:\n"
|
|
460
|
+
" environment:\n"
|
|
461
|
+
" DATABASE_URL: postgresql://postgres:postgres@db:5432/app\n"
|
|
462
|
+
" REDIS_URL: redis://:password@redis:6379/0\n",
|
|
463
|
+
note="Local development defaults.",
|
|
464
|
+
),
|
|
465
|
+
good(
|
|
466
|
+
"src/db.py",
|
|
467
|
+
'URL = f"postgresql://{user}:{password}@{host}:5432/{name}"\n'
|
|
468
|
+
'TEST_URL = "postgresql://scott:tiger@localhost/test"\n',
|
|
469
|
+
),
|
|
470
|
+
good(
|
|
471
|
+
"ci/push.sh",
|
|
472
|
+
'git push "https://x-access-token:${GITHUB_TOKEN}@github.com/acme/site.git"\n',
|
|
473
|
+
),
|
|
474
|
+
],
|
|
475
|
+
"secrets/generic-assignment": [
|
|
476
|
+
bad("src/app/settings.py", f'SECRET_KEY = "{DJANGO_KEY}" # expect\n'),
|
|
477
|
+
bad(
|
|
478
|
+
"config/oauth.yaml",
|
|
479
|
+
"google:\n"
|
|
480
|
+
" client_id: 1234.apps.googleusercontent.com\n"
|
|
481
|
+
f" client_secret: {CLIENT_SECRET} # expect\n",
|
|
482
|
+
),
|
|
483
|
+
bad("web/src/api.js", f"const apiKey = '{API_KEY}'; // expect\n"),
|
|
484
|
+
good(
|
|
485
|
+
"src/app/settings.py",
|
|
486
|
+
'DB_PASSWORD = os.environ["DB_PASSWORD"]\n'
|
|
487
|
+
'API_TOKEN = config("API_TOKEN", default="")\n'
|
|
488
|
+
'PASSWORD_HASH = "$2b$12$' + material("bcrypt", 53, B62 + "./") + '"\n',
|
|
489
|
+
note="References, empty defaults and password hashes.",
|
|
490
|
+
),
|
|
491
|
+
good(
|
|
492
|
+
"src/app/auth.py",
|
|
493
|
+
'TOKEN_URL = "https://oauth2.googleapis.com/token"\n'
|
|
494
|
+
'PASSWORD_FIELD = "user_password"\n'
|
|
495
|
+
'api_key = "your-api-key-here"\n'
|
|
496
|
+
"max_tokens = 4096\n",
|
|
497
|
+
),
|
|
498
|
+
bad(
|
|
499
|
+
"tests/test_auth.py",
|
|
500
|
+
f'password = "{PASSWORD}" # expect\n',
|
|
501
|
+
note="In test files a hit is only a note.",
|
|
502
|
+
),
|
|
503
|
+
good(
|
|
504
|
+
".github/workflows/deploy.yml",
|
|
505
|
+
"env:\n CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}\n",
|
|
506
|
+
note="A reference to a CI secret.",
|
|
507
|
+
),
|
|
508
|
+
],
|
|
509
|
+
"secrets/env-file": [
|
|
510
|
+
bad(
|
|
511
|
+
".env",
|
|
512
|
+
"PORT=3000\n"
|
|
513
|
+
f"DATABASE_PASSWORD={PASSWORD} # expect\n"
|
|
514
|
+
f'JWT_SECRET="{DJANGO_KEY}" # expect\n',
|
|
515
|
+
),
|
|
516
|
+
bad("config/.env.production", f"export SESSION_SECRET={API_KEY} # expect\n"),
|
|
517
|
+
good(
|
|
518
|
+
".env.example",
|
|
519
|
+
"DATABASE_PASSWORD=change-me\nJWT_SECRET=\n",
|
|
520
|
+
note="Templates are meant to be committed.",
|
|
521
|
+
),
|
|
522
|
+
good(
|
|
523
|
+
".env",
|
|
524
|
+
"PORT=3000\n"
|
|
525
|
+
"NODE_ENV=production\n"
|
|
526
|
+
"DATABASE_URL=${DATABASE_URL}\n"
|
|
527
|
+
"VITE_API_URL=https://api.acme.io\n"
|
|
528
|
+
"DB_PASSWORD=postgres\n",
|
|
529
|
+
note="Settings, references, public variables and local defaults.",
|
|
530
|
+
),
|
|
531
|
+
good(
|
|
532
|
+
"release.env",
|
|
533
|
+
"RELEASE_TAG=v0.12.0\n"
|
|
534
|
+
f"RELEASE_COMMITISH={'e27a5d1c' + '0123456789abcdef' * 2}\n"
|
|
535
|
+
f"GIT_REVISION={'9f3b' + '0123456789abcdef' * 2 + '77aa'}\n",
|
|
536
|
+
note="Commit IDs look random but are not secrets.",
|
|
537
|
+
),
|
|
538
|
+
],
|
|
539
|
+
"secrets/credentials-file": [
|
|
540
|
+
bad(".npmrc", f"//registry.npmjs.org/:_authToken={UUID_TOKEN} # expect\n"),
|
|
541
|
+
bad(
|
|
542
|
+
".netrc",
|
|
543
|
+
f"machine api.heroku.com\n login ops@acme.io\n password {UUID_TOKEN} # expect\n",
|
|
544
|
+
),
|
|
545
|
+
bad(
|
|
546
|
+
"deploy/server.key",
|
|
547
|
+
KEY_BLOCK + "\n",
|
|
548
|
+
expect=[("deploy/server.key", 1, "new")],
|
|
549
|
+
),
|
|
550
|
+
good(".npmrc", "//registry.npmjs.org/:_authToken=${NPM_TOKEN}\nalways-auth=true\n"),
|
|
551
|
+
good(
|
|
552
|
+
".pypirc",
|
|
553
|
+
"[distutils]\nindex-servers = pypi\n\n"
|
|
554
|
+
"[pypi]\nusername = __token__\npassword = <your-token>\n",
|
|
555
|
+
),
|
|
556
|
+
good(
|
|
557
|
+
"credentials.json.template",
|
|
558
|
+
'{"installed": {"client_id": "ID", "client_secret": "SECRET"}}\n',
|
|
559
|
+
),
|
|
560
|
+
],
|
|
561
|
+
}
|