oauthlint-rules 0.2.5 → 0.2.6

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oauthlint-rules",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "Semgrep rules catching the OAuth/OIDC/JWT anti-patterns that AI coding tools systematically produce.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -0,0 +1,70 @@
1
+ rules:
2
+ - id: auth.flow.secret-in-response
3
+ languages:
4
+ - javascript
5
+ - typescript
6
+ severity: ERROR
7
+ message: |
8
+ A server-side secret read from `process.env` flows into an HTTP
9
+ response body. Whatever you put in `res.send` / `res.json` / `res.end`
10
+ ships straight to the client, so returning a credential here publishes
11
+ it to every caller — it ends up in the browser, in proxies, and in any
12
+ logged response (CWE-200, Sensitive Information Exposure).
13
+
14
+ Never send a server secret to the client. Return only the data the
15
+ caller needs; if the response must reference a credential, send a
16
+ non-sensitive identifier (a key id, the last four characters) or a
17
+ redacted/masked value instead. Keep API keys, passwords, tokens, and
18
+ private keys server-side only.
19
+ # Reverse-direction taint rule: the SOURCE is the secret (a `process.env.*`
20
+ # value whose NAME looks like a credential) and the SINK is the Express
21
+ # response body — the opposite of the request->sink flow rules (ssrf,
22
+ # open-redirect). Taint mode catches indirection: `const k =
23
+ # process.env.API_KEY; res.send(k)` flags, not just the inline form.
24
+ #
25
+ # Low-FP control is the source NAME regex: it requires a credential-shaped
26
+ # name AND excludes the client-public prefixes (PUBLIC_, NEXT_PUBLIC_,
27
+ # VITE_, REACT_APP_, EXPO_PUBLIC_) whose values are exposed to the browser
28
+ # by design — sending those back is not a leak. Distinct from
29
+ # auth.secret.public-env-secret, which is a build-time *exposure* check on
30
+ # the env-var name alone; this rule is a *runtime dataflow* into a response.
31
+ mode: taint
32
+ pattern-sources:
33
+ # process.env.SECRET_NAME — member-access form.
34
+ - patterns:
35
+ - pattern: process.env.$KEY
36
+ - metavariable-regex:
37
+ metavariable: $KEY
38
+ regex: (?i)^(?!(?:NEXT_PUBLIC|EXPO_PUBLIC|REACT_APP|PUBLIC|VITE)_).*(?:secret|password|passwd|token|api[_-]?key|private[_-]?key|client[_-]?secret|credential|access[_-]?key).*$
39
+ # process.env['SECRET_NAME'] — index form.
40
+ - patterns:
41
+ - pattern: process.env[$K]
42
+ - metavariable-regex:
43
+ metavariable: $K
44
+ regex: (?i)^(?!(?:NEXT_PUBLIC|EXPO_PUBLIC|REACT_APP|PUBLIC|VITE)_).*(?:secret|password|passwd|token|api[_-]?key|private[_-]?key|client[_-]?secret|credential|access[_-]?key).*$
45
+ pattern-sanitizers:
46
+ # Routing the value through a redaction/masking helper clears the taint:
47
+ # the masked/redacted form is no longer the live secret.
48
+ - pattern: redact(...)
49
+ - pattern: mask(...)
50
+ pattern-sinks:
51
+ - patterns:
52
+ - pattern-either:
53
+ - pattern: $RES.send($X)
54
+ - pattern: $RES.json($X)
55
+ - pattern: $RES.jsonp($X)
56
+ - pattern: $RES.end($X)
57
+ - pattern: $RES.write($X)
58
+ - focus-metavariable: $X
59
+ metadata:
60
+ oauthlint-rule-id: AUTH-FLOW-012
61
+ oauthlint-doc-url: https://oauthlint.dev/rules/flow-secret-in-response
62
+ category: security
63
+ cwe: CWE-200
64
+ owasp: API3:2023
65
+ llm-prevalence: HIGH
66
+ technology:
67
+ - express
68
+ references:
69
+ - https://cwe.mitre.org/data/definitions/200.html
70
+ - https://owasp.org/API-Security/editions/2023/en/0xa3-broken-object-property-level-authorization/
@@ -0,0 +1,69 @@
1
+ rules:
2
+ - id: auth.go.flow.secret-in-response
3
+ languages:
4
+ - go
5
+ severity: ERROR
6
+ message: |
7
+ A server-side secret read from the environment flows into an HTTP
8
+ response body, leaking it to the client. Values such as an API key,
9
+ client secret, access key, or private key are meant to stay on the
10
+ server; writing one to the `http.ResponseWriter` (via `Write`,
11
+ `fmt.Fprint(f)`, `io.WriteString`, or a JSON encoder) publishes it to
12
+ every caller — including attackers probing your endpoints.
13
+
14
+ Never return a credential to the client. Send only the data the caller
15
+ legitimately needs; if a secret must appear in a debug/diagnostic path,
16
+ redact or mask it first. Read secrets exclusively in server-internal
17
+ code and keep them out of any response payload. See CWE-200.
18
+ # Reverse-direction taint: the SOURCE is the secret (an os.Getenv /
19
+ # os.LookupEnv read whose key name looks like a credential) and the SINK is
20
+ # the HTTP response. Taint mode so indirection (s := os.Getenv("API_KEY");
21
+ # w.Write([]byte(s))) is caught, not just the inline form. The taint is
22
+ # cleared by a redaction/mask helper before the value reaches the response.
23
+ mode: taint
24
+ pattern-sources:
25
+ # $KEY is the env-var name literal. The metavariable-regex keeps only
26
+ # names that look like a credential, while a single negative lookahead
27
+ # excludes client-public prefixes (PUBLIC_ / NEXT_PUBLIC_) — those ship to
28
+ # the browser by design and are not server secrets.
29
+ - patterns:
30
+ - pattern-either:
31
+ - pattern: os.Getenv($KEY)
32
+ - pattern: os.LookupEnv($KEY)
33
+ - metavariable-regex:
34
+ metavariable: $KEY
35
+ regex: (?i)^(?!"?(next_)?public_)"?.*(secret|password|passwd|token|api[_-]?key|private[_-]?key|client[_-]?secret|credential|access[_-]?key).*"?$
36
+ pattern-sanitizers:
37
+ # A redaction/mask helper clears the taint: the value written to the
38
+ # response is no longer the raw secret.
39
+ - pattern: redact(...)
40
+ - pattern: mask(...)
41
+ pattern-sinks:
42
+ # Focus the value argument so the finding lands on the leaked secret, not
43
+ # the whole call. Plain-call forms (no aliasing) match reliably in taint
44
+ # mode. $W is the http.ResponseWriter.
45
+ - patterns:
46
+ - pattern-either:
47
+ - pattern: $W.Write($X)
48
+ - pattern: fmt.Fprint($W, $X)
49
+ - pattern: fmt.Fprintf($W, $FMT, $X)
50
+ - pattern: io.WriteString($W, $X)
51
+ - pattern: json.NewEncoder($W).Encode($X)
52
+ # The env-read SOURCE shapes are disjoint from these response sinks,
53
+ # but exclude them explicitly so an env read is only ever a source,
54
+ # never re-counted as a sink.
55
+ - pattern-not: os.Getenv(...)
56
+ - pattern-not: os.LookupEnv(...)
57
+ - focus-metavariable: $X
58
+ metadata:
59
+ oauthlint-rule-id: AUTH-GO-FLOW-004
60
+ oauthlint-doc-url: https://oauthlint.dev/rules/go-flow-secret-in-response
61
+ category: security
62
+ cwe: CWE-200
63
+ owasp: API3:2023
64
+ llm-prevalence: HIGH
65
+ technology:
66
+ - net/http
67
+ references:
68
+ - https://cwe.mitre.org/data/definitions/200.html
69
+ - https://owasp.org/API-Security/editions/2023/en/0xa3-broken-object-property-level-authorization/
@@ -0,0 +1,88 @@
1
+ rules:
2
+ - id: auth.py.flow.secret-in-response
3
+ languages:
4
+ - python
5
+ severity: ERROR
6
+ message: |
7
+ A server-side secret read from the environment flows into an HTTP
8
+ response sent back to the client — leaking it (CWE-200). Anything you
9
+ return from a Flask view (via `jsonify(...)`, `make_response(...)`,
10
+ `Response(...)`) is visible to every caller, so an env value whose name
11
+ looks like a credential (`API_KEY`, `CLIENT_SECRET`, `*_TOKEN`,
12
+ `*_PASSWORD`, a private key, an access key, ...) must never reach it.
13
+
14
+ Never send a server secret to the client. Return only the data the
15
+ caller needs; keep credentials server-side. If a value genuinely must be
16
+ surfaced, redact or mask it first (`redact(...)` / `mask_secret(...)`),
17
+ and prefer exposing only public configuration (names prefixed
18
+ `PUBLIC_` / `NEXT_PUBLIC_` / `VITE_`) to clients.
19
+ # REVERSE-direction taint: the SOURCE is the secret (an os.environ / getenv
20
+ # value whose name looks like a credential), the SINK is the HTTP response.
21
+ # Taint mode so indirection (secret = os.getenv('CLIENT_SECRET');
22
+ # return jsonify(secret=secret)) is caught, not just the inline form.
23
+ # `metavariable-regex` constrains the env var NAME to credential-looking
24
+ # words while excluding public-by-convention prefixes, and passing the value
25
+ # through a redaction/mask helper clears the taint. The sink focuses the
26
+ # response value argument. `by-side-effect` is unsupported on semgrep 1.157,
27
+ # so the source is constrained inline rather than via a propagator.
28
+ mode: taint
29
+ pattern-sources:
30
+ - patterns:
31
+ - pattern-either:
32
+ - pattern: os.environ[$KEY]
33
+ - pattern: os.environ.get($KEY)
34
+ - pattern: 'os.environ.get($KEY, ...)'
35
+ - pattern: os.getenv($KEY)
36
+ - pattern: 'os.getenv($KEY, ...)'
37
+ # Qualified `from os import environ, getenv` forms.
38
+ - pattern: environ[$KEY]
39
+ - pattern: environ.get($KEY)
40
+ - pattern: 'environ.get($KEY, ...)'
41
+ - pattern: getenv($KEY)
42
+ - pattern: 'getenv($KEY, ...)'
43
+ # $KEY must look like a credential AND must not be a public-by-
44
+ # convention name. A single regex: a negative lookahead drops the
45
+ # PUBLIC_/NEXT_PUBLIC_/VITE_ prefixes (so NEXT_PUBLIC_API_KEY is NOT a
46
+ # source), then a credential keyword must appear. The optional leading
47
+ # quote tolerates semgrep binding the string literal with or without
48
+ # its quotes; `(?i)` makes the whole match case-insensitive.
49
+ - metavariable-regex:
50
+ metavariable: $KEY
51
+ regex: '(?i)^[''"]?(?!(?:NEXT_PUBLIC_|VITE_|PUBLIC_))\w*(?:secret|password|passwd|token|api[_-]?key|private[_-]?key|client[_-]?secret|credential|access[_-]?key)'
52
+ pattern-sanitizers:
53
+ # Redaction / masking helpers: a secret passed through one of these is no
54
+ # longer sensitive, so returning the result is safe.
55
+ - pattern: redact(...)
56
+ - pattern: mask(...)
57
+ - pattern: mask_secret(...)
58
+ pattern-sinks:
59
+ - patterns:
60
+ - pattern-either:
61
+ # Flask response constructors — the reliable sinks. Each covers a
62
+ # positional value and a keyword value (jsonify(secret=...)), and
63
+ # taint reaching a value nested inside (e.g. a dict) still fires.
64
+ - pattern: 'jsonify(..., $X, ...)'
65
+ - pattern: 'jsonify(..., $K=$X, ...)'
66
+ - pattern: 'flask.jsonify(..., $X, ...)'
67
+ - pattern: 'flask.jsonify(..., $K=$X, ...)'
68
+ - pattern: 'make_response(..., $X, ...)'
69
+ - pattern: 'make_response(..., $K=$X, ...)'
70
+ - pattern: 'flask.make_response(..., $X, ...)'
71
+ - pattern: 'flask.make_response(..., $K=$X, ...)'
72
+ - pattern: 'Response(..., $X, ...)'
73
+ - pattern: 'Response(..., $K=$X, ...)'
74
+ - pattern: 'flask.Response(..., $X, ...)'
75
+ - pattern: 'flask.Response(..., $K=$X, ...)'
76
+ - focus-metavariable: $X
77
+ metadata:
78
+ oauthlint-rule-id: AUTH-PY-FLOW-008
79
+ oauthlint-doc-url: https://oauthlint.dev/rules/py-flow-secret-in-response
80
+ category: security
81
+ cwe: CWE-200
82
+ owasp: API3:2023
83
+ llm-prevalence: HIGH
84
+ technology:
85
+ - flask
86
+ references:
87
+ - https://cwe.mitre.org/data/definitions/200.html
88
+ - https://owasp.org/API-Security/editions/2023/en/0xa3-broken-object-property-level-authorization/
@@ -0,0 +1,48 @@
1
+ rules:
2
+ - id: auth.py.jwt.algorithm-confusion
3
+ languages:
4
+ - python
5
+ severity: ERROR
6
+ message: |
7
+ A JWT is decoded with an `algorithms` allowlist that mixes a symmetric
8
+ HMAC algorithm (HS256/HS384/HS512) with an asymmetric one (RS*/ES*/PS*).
9
+ This enables the "algorithm confusion" attack: an attacker who knows your
10
+ RSA/EC PUBLIC key can sign a forged token with HMAC, using that public key
11
+ string as the shared secret. Because HS* is also accepted, PyJWT verifies
12
+ the forgery with the public key as the HMAC secret and treats it as valid
13
+ — a complete authentication bypass.
14
+
15
+ Allow only ONE algorithm family — the one you actually use. If you issue
16
+ RS256 tokens, pin `jwt.decode(token, public_key, algorithms=["RS256"])`
17
+ and never also accept an HS* algorithm with the same verification key.
18
+
19
+ CWE-327: Use of a Broken or Risky Cryptographic Algorithm.
20
+ # Distinct from auth.py.jwt.no-algorithms (which flags a MISSING `algorithms`
21
+ # allowlist): here the allowlist is PRESENT but dangerously MIXES a symmetric
22
+ # (HS*) and an asymmetric (RS*/ES*/PS*) family in the same `jwt.decode` call.
23
+ #
24
+ # A single metavariable-regex over the bound list literal `$ALGS` requires
25
+ # BOTH families to appear (order-independent lookaheads), so single-family
26
+ # lists like ["RS256"] or ["HS256"] never match. `(?s)` lets `.` span a
27
+ # multi-line list. The `import jwt` guard pins this to PyJWT (joserfc and
28
+ # other libs expose a different `jwt.decode`).
29
+ patterns:
30
+ - pattern: jwt.decode(..., algorithms=$ALGS, ...)
31
+ - metavariable-regex:
32
+ metavariable: $ALGS
33
+ regex: (?s)(?=.*['"]HS(256|384|512)['"])(?=.*['"](RS|ES|PS)(256|384|512)['"])
34
+ - pattern-inside: |
35
+ import jwt
36
+ ...
37
+ metadata:
38
+ oauthlint-rule-id: AUTH-PY-JWT-006
39
+ oauthlint-doc-url: https://oauthlint.dev/rules/py-jwt-algorithm-confusion
40
+ category: security
41
+ cwe: CWE-327
42
+ owasp: API2:2023
43
+ llm-prevalence: MEDIUM
44
+ technology:
45
+ - PyJWT
46
+ references:
47
+ - https://cwe.mitre.org/data/definitions/327.html
48
+ - https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/
@@ -0,0 +1,50 @@
1
+ rules:
2
+ - id: auth.rust.jwt.algorithm-confusion
3
+ languages:
4
+ - rust
5
+ severity: ERROR
6
+ message: |
7
+ A `jsonwebtoken` `Validation` accepts a list of algorithms that MIXES an
8
+ HMAC family (`Algorithm::HS256`/`HS384`/`HS512`) with an asymmetric family
9
+ (`Algorithm::RS*`/`ES*`/`PS*`). This is the "algorithm confusion" attack:
10
+ when both families are accepted, an attacker takes your RSA/EC PUBLIC key
11
+ (which is not secret) and signs a forged token with HS*, using the public
12
+ key bytes as the HMAC shared secret. `decode` then verifies that forged
13
+ token as valid, letting the attacker mint arbitrary identities and claims.
14
+
15
+ Pin `validation.algorithms` to a SINGLE family you actually use, e.g.
16
+ `validation.algorithms = vec![Algorithm::RS256];` when your issuer signs
17
+ with RSA, or `vec![Algorithm::HS256]` for a genuinely symmetric secret.
18
+ Never accept an HMAC algorithm alongside an asymmetric one.
19
+
20
+ CWE-327: use of a broken or risky cryptographic algorithm/configuration.
21
+ # Algorithm confusion = the accepted-algorithm list mixes an HMAC variant
22
+ # (HS*) with an asymmetric variant (RS*/ES*/PS*). We bind the algorithm list
23
+ # expression to $VEC — set either via the public `algorithms` field or via a
24
+ # `set_algorithms(...)` call — and require, with two ANDed metavariable-regex
25
+ # constraints, that its source text contains BOTH an `Algorithm::HS*` AND an
26
+ # `Algorithm::RS*|ES*|PS*` variant. Order-independent (no ellipsis-in-macro
27
+ # fragility) and inherently low-FP: a single-family list such as
28
+ # `vec![Algorithm::RS256]` fails the HS* constraint and is never flagged.
29
+ patterns:
30
+ - pattern-either:
31
+ - pattern: $V.algorithms = $VEC;
32
+ - pattern: $V.set_algorithms($VEC)
33
+ - metavariable-regex:
34
+ metavariable: $VEC
35
+ regex: '(?s).*Algorithm::HS(256|384|512)'
36
+ - metavariable-regex:
37
+ metavariable: $VEC
38
+ regex: '(?s).*Algorithm::(RS|ES|PS)(256|384|512)'
39
+ metadata:
40
+ oauthlint-rule-id: AUTH-RUST-JWT-006
41
+ oauthlint-doc-url: https://oauthlint.dev/rules/rust-jwt-algorithm-confusion
42
+ category: security
43
+ cwe: CWE-327
44
+ owasp: API2:2023
45
+ llm-prevalence: MEDIUM
46
+ technology:
47
+ - jsonwebtoken
48
+ references:
49
+ - https://cwe.mitre.org/data/definitions/327.html
50
+ - https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/