Secrets and crypto review

From makifbaysal/tasktrooper · View interactive version

Secrets and crypto review is an AI agent skill from the GitHub repository makifbaysal/tasktrooper. Use when the diff adds or moves a credential, logs or returns data, builds a URL or argv with a token, generates a random value, encrypts, signs, hashes, configures TLS or writes a credential file

How to use this skill

Skill file

Secrets and Crypto Review

Overview

A committed secret is leaked the moment the branch is pushed; deleting it in a later commit does not un-leak it. Crypto bugs are the opposite: invisible in behaviour, obvious in the parameters. Both are found by reading values, not flows.

Core principle: secrets live only in the secret store and in memory; crypto parameters are chosen by the library's safe default, never hand-assembled.

1. Live Secrets in Code (CWE-798) — a blocking category

Recognisable shapes: AKIA…/ASIA… (AWS), ghp_/github_pat_/gho_ (GitHub), xoxb-/xoxp- (Slack), sk_live_/rk_live_ (Stripe), -----BEGIN … PRIVATE KEY-----, a GCP service-account JSON ("type": "service_account"), a database URL with a password, a JWT signing secret, a committed .env, kubeconfig, .npmrc with _authToken, ~/.docker/config.json.

Decide whether it is live before blocking:

2. Secrets Where They Leak

// ❌ token on argv — visible to every local user via ps and /proc
exec.Command("curl", "-H", "Authorization: Bearer "+token, url)
// ✅ the child reads it from its environment or stdin
cmd := exec.Command("curl", "-H", "@-", url); cmd.Stdin = strings.NewReader("Authorization: Bearer " + token)

3. Randomness (CWE-338)

// ❌
const token = Math.random().toString(36).slice(2);
// ✅
const token = crypto.randomBytes(32).toString("base64url");

| Stack | ❌ for secrets | ✅ |

|-------|----------------|----|

| Go | math/rand, math/rand/v2 | crypto/rand (rand.Text() in Go 1.24+) |

| Python | random | secrets.token_urlsafe, secrets.token_bytes |

| JVM | java.util.Random, kotlin.random.Random | SecureRandom |

| Node / browser | Math.random | crypto.randomBytes, crypto.randomUUID, crypto.getRandomValues |

| C# | System.Random | RandomNumberGenerator |

Weak randomness is a finding only when the value is a secret: session ids, reset tokens, API keys, nonces, invite codes. Shuffling a UI list is not.

4. Encryption and Hashing (CWE-327, CWE-328, CWE-329)

// ❌ ECB by default, static key
Cipher c = Cipher.getInstance("AES");
// ✅ AEAD with a fresh random 12-byte nonce per message
Cipher c = Cipher.getInstance("AES/GCM/NoPadding");
c.init(Cipher.ENCRYPT_MODE, key, new GCMParameterSpec(128, nonce));

5. TLS Verification Disabled (CWE-295)

InsecureSkipVerify: true (Go), verify=False (requests/httpx), rejectUnauthorized: false or NODE_TLS_REJECT_UNAUTHORIZED=0 (Node), a trust-all X509TrustManager or HostnameVerifier returning true (JVM), ServerCertificateCustomValidationCallback = (…) => true (.NET), URLSession delegates that accept any challenge (iOS). A finding when it is in a production code path talking to real hosts; a local test harness is excluded.

6. Credential Files (CWE-276, CWE-732)

// ❌ world-readable token file
os.WriteFile(path, token, 0o644)
// ✅
os.WriteFile(path, token, 0o600)

Python: open() respects the umask — use os.open(path, os.O_WRONLY | os.O_CREAT, 0o600). Only a finding on multi-user machines or shared volumes; say which.

Severity Guide

Live production secret in code → CRITICAL. Secret in logs or error bodies reachable by other users → HIGH. TLS verification disabled on a production path → HIGH. Weak randomness for session or reset tokens → HIGH. ECB/static IV on data at rest → MEDIUM to HIGH by what it protects.

Common Mistakes

Red Flags

References (names and links only)

OWASP Top 10:2025 A04 Cryptographic Failures, A07 Authentication Failures, A09 Security Logging and Alerting Failures · ASVS 5.0 V11 Cryptography, V13 Configuration, V14 Data Protection · CWE-209, 214, 276, 295, 327, 328, 329, 338, 532, 598, 798

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.