Code review

How to block weak RSA and ECC regressions in CI and PR review

Capy team

Block P-256, Ed25519 and RSA-2048 regressions with four layers: AST rules in CI, Capy Review on PRs, config lints on certs, JWKS and proxies, and a TLS 1.3 X25519MLKEM768 smoke test. Start in warning mode, clear existing hits, allowlist legacy verification with expiry dates, then flip to error.

How to block weak RSA and ECC across four layers

Copied TLS configs and defaults reintroduce P-256, Ed25519 and RSA-2048 soon after a post-quantum cryptography (PQC) migration. To hold the floor in the NSA December 2026 PQC checklist, enforce four layers.

LayerToolingBlocksMisses
AST rulesast-grep, SemgrepP-256, X25519, Ed25519, RSA under 3072Variables, wrappers
PR reviewCapy ReviewVariables, wrappers, ALB defaultsCode outside diff
Config lintopenssl x509, grepWeak certs, JWKS, proxy curvesMulti-line YAML
TLS smokeOpenSSL 3.5+, GoOpenSSL 3.0, failed X25519MLKEM768Offline signing

How to block P-256, Ed25519 and RSA-2048 with AST rules

Point sgconfig.yml at ruleDirs: [rules/pqc] using ast-grep and run ast-grep scan on pull_request. Use kind: selector_expression with a regex in rules/pqc/go-weak-ecc.yml because plain patterns like tls.CurveP256 miss composite literals in ast-grep's Go grammar; tls.X25519MLKEM768 does not match:

id: go-weak-ecc
language: go
severity: error
message: 256-bit curve. Use X25519MLKEM768, P-384 or ML-DSA.
rule:
  kind: selector_expression
  any:
    - regex: '^(elliptic|ecdh)\.P256$'
    - regex: '^(ecdh|tls)\.X25519$'
    - regex: '^tls\.CurveP256$'
    - regex: '^ed25519\.GenerateKey$'

In rules/pqc/go-rsa-size.yml, the regex matches every integer literal 0 to 3071, so 2560 fails as well as 2048; a size in a variable needs the review layer:

id: go-rsa-under-3072
language: go
severity: error
message: RSA keys under 3072 bits are below the NSA interim size.
rule:
  pattern: rsa.GenerateKey($R, $BITS)
constraints:
  BITS:
    regex: '^([0-9]{1,3}|[12][0-9]{3}|30[0-6][0-9]|307[01])$'

Add rules in rules/pqc for TypeScript JWT alg pairs and Node.js or Python cryptography. With Semgrep, metavariable-comparison enforces $BITS < 3072, since use-of-weak-rsa-key only flags RSA keys under 2048 bits.

How to enforce post-quantum rules on every PR with Capy

Syntax rules miss variables, wrappers and defaults like an AWS ALB HTTPS listener falling back to ELBSecurityPolicy-2016-08. Add these bullets under a ## Reviews heading in AGENTS.md so Capy Review flags regressions on every PR:

- Flag new 256-bit elliptic curves (P-256, secp256r1, prime256v1,
  standalone X25519) for key exchange or signing. X25519MLKEM768
  is allowed.
- Flag new Ed25519 or EdDSA key generation and EdDSA JWT signing.
- Flag RSA keys or certificate requests under 3072 bits. Accept
  RSA-3072 or P-384 as interim sizes and ML-DSA as the target.
- Flag TLS listeners or clients that omit X25519MLKEM768, TLS
  1.2-only listeners, and AWS ALB HTTPS listeners without an
  explicit PQ security policy.
- Flag new ES256 or RS256 JWT signing. Require ES384, PS384 or
  ML-DSA-65.
- Ignore test fixtures under testdata/ and code that only verifies
  legacy signatures during a dual-key rotation window.
  • PR and org rules. Capy Review enforces AGENTS.md and org-wide rules in Settings → Review or the review rules API, posting inline comments with incremental re-reviews.
  • Multi-repo cleanup. Captains split work into one thread per repo, each opening and following its own PR as in the multi-repo guide.
  • Isolated cloud microVMs. Each thread clones the repo on its own cloud machine, runs real tests and TLS checks before opening the PR, and wakes to fix findings.
  • Scheduled re-scans. Automations run a weekly prompt that opens a PR on weak crypto. Capy never merges unless asked.

How to lint certificates, JWKS files and proxy configs in CI

Audit existing keys with the JWT, SSH and certificate audit guide, then run three heuristic greps:

  • Certs. Fail openssl x509 -noout -text on *.crt/*.pem matching prime256v1 or 1024/2048-bit RSA.
  • JWKS. Fail when jq -e '.keys[] | select(.crv == "P-256" or .kty == "OKP")' finds a key in any *jwks*.json, minified or not.
  • Proxies. Fail *.conf, *.yaml and *.yml files setting nginx ssl_ecdh_curve or Envoy ecdh_curves without X25519MLKEM768.

These miss multi-line YAML, templates and runtime libraries, which handshake tests and Capy Review catch.

How to verify X25519MLKEM768 handshakes in CI

Config strings fail on OpenSSL 3.0, which lacks ML-KEM. Boot the service, run a bounded 60-second wait on localhost port 8443, and run openssl s_client restricted to X25519MLKEM768. The client needs OpenSSL 3.5+ and exits non-zero on failure:

openssl version
./bin/my-service &
SERVER_PID=$!
trap 'kill "$SERVER_PID"' EXIT

for i in $(seq 60); do
  (exec 3<>/dev/tcp/localhost/8443) 2>/dev/null && break
  sleep 1
done
openssl s_client -connect localhost:8443 \
  -groups X25519MLKEM768 -tls1_3 < /dev/null

On Go 1.25+, assert ConnectionState.CurveID in go test. Keep the test in the same package as HybridTLSConfig() so editing that config fails the test (imports: crypto/tls, net/http, net/http/httptest, testing):

func TestPQHandshake(t *testing.T) {
	h := http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})
	srv := httptest.NewUnstartedServer(h)
	srv.TLS = HybridTLSConfig()
	srv.StartTLS()
	defer srv.Close()

	resp, err := srv.Client().Get(srv.URL)
	if err != nil {
		t.Fatal(err)
	}
	defer resp.Body.Close()

	if got := resp.TLS.CurveID; got != tls.X25519MLKEM768 {
		t.Fatalf("got curve %v, want X25519MLKEM768", got)
	}
}

Node.js 24.22.3 ships OpenSSL 3.5.9, where socket.getEphemeralKeyInfo() returns { type: 'TLSGroup', name: 'X25519MLKEM768' }, and Python 3.15 on OpenSSL 3.5.9 returns 'X25519MLKEM768' from SSLSocket.group(). See the post-quantum TLS 1.3 guide.

How to roll out PQC CI gates without stalling PRs

  1. Warn first. Set severity: warning in ast-grep and keep config lints non-blocking to count hits on main.
  2. Burn down hits. Group repos in one Capy project, mark quiet repos lazy, and let a Captain open one PR per repo.
  3. Allowlist dual-key paths. Put ES256 or Ed25519 verification in dedicated files with an expiry comment, and mirror that in AGENTS.md.
  4. Flip to error. Restore severity: error once clear, require the TLS smoke test, and schedule a weekly Capy automation.

Frequently Asked Questions

Why should CI allow X25519MLKEM768 while blocking standalone X25519?+
Standalone X25519 is a 256-bit curve NSA PP-26-4956 excludes. X25519MLKEM768 is an RFC 10024 hybrid whose ML-KEM-768 half supplies post-quantum security.
Why does Semgrep's default Go RSA rule miss RSA-2048 keys?+
use-of-weak-rsa-key only flags keys under 2048 bits, below the RSA-3072 interim floor. Add an ast-grep rule or Semgrep metavariable-comparison against 3072.
Can a default Linux CI runner execute the OpenSSL TLS 1.3 smoke test?+
Run openssl version first because LTS Linux runners often ship OpenSSL 3.0 without ML-KEM. Use OpenSSL 3.5+, Go 1.25+, Node.js 24.22.3 or Python 3.15.
How do we allow legacy signature verification during a dual-key window?+
Isolate ES256 or Ed25519 verification in dedicated files, exclude those paths with an expiry comment, and mirror the exception in AGENTS.md.

Sources

  1. NSA: Immediate Actions to Push Toward Post-Quantum (PP-26-4956)
  2. ast-grep docs: Rule configuration
  3. Semgrep docs: Rule syntax
  4. Capy docs: Reviews

Spotted something out of date? Tell us at support@capy.ai.

Block weak crypto on every pull request

Add plain-English post-quantum rules in AGENTS.md or Settings → Review so Capy flags regressions on the changed lines.