# canonicalization-order-v1

> canonicalization-order-v1: 4 Keryn rules for python, typescript, javascript, go, php (4 error).

Source: https://keryn.dev/rules/canonicalization-order-v1/

4 rules · Keryn Software Licence · rules 0.8.0 · [all packs](https://keryn.dev/rules/)

**How to read a rule**

- **Severity**: How bad the finding is if it is real: `error` fails a default gate, `warning` and `info` do not.

- **Confidence**: **P0** exploitable as written; **P1** dangerous in context; **P2** a heuristic or a posture check: confirm by reading the code.

- **False-positive risk**: **low**: an exact API or flag, so hits are almost always real; **medium**: the pattern is legitimate in many programs, so check each hit; **high**: it finds a lead to confirm, so expect benign hits.

- **Edge**: The relationship the finding sits on. **reaches**: content or traffic gets to a thing; **calls**: one thing invokes another; **reads**: one thing reads from another; **writes**: one thing writes to another; **sends**: data leaves for another party; **grants**: authority is given or left unchecked; **depends_on**: something relies on a component it does not verify; **trusts**: one party believes another without evidence. The boundary it crosses, when there is one: **user->prompt** (untrusted input reaching a prompt); **model->code** (model output reaching code, a shell, a query or a page); **secret->outside** (a secret leaving the trusted side); **supply-chain** (code, models or prompts pulled in from outside).

- **Taxonomy chips**: References for readers who work in OWASP LLM 2025, OWASP Agentic, CWE or NIST AI RMF. They say where a rule belongs, not that a framework is satisfied.

## keryn.canon.py.validate-before-decode

`error` python python

A value is validated or allow-listed, then decoded/normalized (unquote, b64decode, realpath, normalize), then the decoded result reaches a path/command/URL sink. The check ran on the pre-decode bytes, so encoded input (%2e%2e, double-encoding) passes the guard and the sink sees something else. Validate after you fully decode and normalize, on the final value.

Confidence **P1**: dangerous in context. False-positive risk **medium**: the pattern is legitimate in many programs, so check each hit.

Edge inspected: [trusts](https://keryn.dev/docs/edges/edge-kinds/#trusts) one party believes another without evidence.

[CWE-179](https://keryn.dev/rules/?cwe=CWE-179) [CWE-180](https://keryn.dev/rules/?cwe=CWE-180) [CWE-20](https://keryn.dev/taxonomies/cwe/#cwe-20-improper-input-validation) [LLM01](https://keryn.dev/taxonomies/owasp-llm/#llm01-prompt-injection) [ASI02](https://keryn.dev/taxonomies/owasp-agentic/#asi02-tool-misuse-and-exploitation)

**Fix:** Decode and normalize first, then validate the final value: resolve the path with os.path.realpath and confirm it is inside the allowed root; URL-decode fully (checking for double-encoding) before matching an allow-list; then pass that same value to the sink.

**References:** [https://cwe.mitre.org/data/definitions/179.html](https://cwe.mitre.org/data/definitions/179.html) · [https://docs.python.org/3/library/urllib.parse.html#urllib.parse.unquote](https://docs.python.org/3/library/urllib.parse.html#urllib.parse.unquote) · [https://docs.python.org/3/library/os.path.html#os.path.realpath](https://docs.python.org/3/library/os.path.html#os.path.realpath)

## keryn.canon.ts.validate-before-decode

`error` typescript, javascript typescript, nodejs

A value is validated or allow-listed, then decoded/normalized (decodeURIComponent, unescape, path.resolve, normalize), then the decoded result reaches a path/command/URL sink. The check ran on the pre-decode bytes, so encoded input slips past it. Decode and normalize first, then validate the final value before the sink.

Confidence **P1**: dangerous in context. False-positive risk **medium**: the pattern is legitimate in many programs, so check each hit.

Edge inspected: [trusts](https://keryn.dev/docs/edges/edge-kinds/#trusts) one party believes another without evidence.

[CWE-179](https://keryn.dev/rules/?cwe=CWE-179) [CWE-180](https://keryn.dev/rules/?cwe=CWE-180) [CWE-20](https://keryn.dev/taxonomies/cwe/#cwe-20-improper-input-validation) [LLM01](https://keryn.dev/taxonomies/owasp-llm/#llm01-prompt-injection) [ASI02](https://keryn.dev/taxonomies/owasp-agentic/#asi02-tool-misuse-and-exploitation)

**Fix:** Decode and normalize first, then validate: resolve the path and confirm it stays inside the allowed root, fully URL-decode before matching an allow-list, then pass that value to the sink.

**References:** [https://cwe.mitre.org/data/definitions/179.html](https://cwe.mitre.org/data/definitions/179.html) · [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent) · [https://nodejs.org/api/path.html#pathresolvepaths](https://nodejs.org/api/path.html#pathresolvepaths)

## keryn.canon.go.validate-before-decode

`error` go go

A value is validated/allow-listed, then decoded or normalized (QueryUnescape, filepath.Clean), then the decoded result reaches a path/command/request sink. The check ran on pre-decode bytes. Decode and normalize first, then validate the final value before the sink.

Confidence **P1**: dangerous in context. False-positive risk **medium**: the pattern is legitimate in many programs, so check each hit.

Edge inspected: [trusts](https://keryn.dev/docs/edges/edge-kinds/#trusts) one party believes another without evidence.

[CWE-179](https://keryn.dev/rules/?cwe=CWE-179) [CWE-180](https://keryn.dev/rules/?cwe=CWE-180) [CWE-20](https://keryn.dev/taxonomies/cwe/#cwe-20-improper-input-validation) [LLM01](https://keryn.dev/taxonomies/owasp-llm/#llm01-prompt-injection) [ASI02](https://keryn.dev/taxonomies/owasp-agentic/#asi02-tool-misuse-and-exploitation)

**Fix:** Decode and normalize first (url.QueryUnescape, filepath.Clean), then validate the final value and confirm it stays inside the allowed root before the sink.

**References:** [https://cwe.mitre.org/data/definitions/179.html](https://cwe.mitre.org/data/definitions/179.html) · [https://pkg.go.dev/net/url#QueryUnescape](https://pkg.go.dev/net/url#QueryUnescape)

## keryn.canon.php.validate-before-decode

`error` php php

A value is validated/allow-listed, then decoded or normalized (urldecode, rawurldecode, realpath), then the decoded result reaches a path/command/request sink. The check ran on pre-decode bytes. Decode and normalize first, then validate the final value before the sink.

Confidence **P1**: dangerous in context. False-positive risk **medium**: the pattern is legitimate in many programs, so check each hit.

Edge inspected: [trusts](https://keryn.dev/docs/edges/edge-kinds/#trusts) one party believes another without evidence.

[CWE-179](https://keryn.dev/rules/?cwe=CWE-179) [CWE-180](https://keryn.dev/rules/?cwe=CWE-180) [CWE-20](https://keryn.dev/taxonomies/cwe/#cwe-20-improper-input-validation) [LLM01](https://keryn.dev/taxonomies/owasp-llm/#llm01-prompt-injection) [ASI02](https://keryn.dev/taxonomies/owasp-agentic/#asi02-tool-misuse-and-exploitation)

**Fix:** Decode and normalize first (rawurldecode, realpath), then validate the final value and confirm it stays inside the allowed root before the sink.

**References:** [https://cwe.mitre.org/data/definitions/179.html](https://cwe.mitre.org/data/definitions/179.html) · [https://www.php.net/manual/en/function.rawurldecode.php](https://www.php.net/manual/en/function.rawurldecode.php)
