# state-transition-integrity-v1

> state-transition-integrity-v1: 8 Keryn rules for python, typescript, javascript, go (8 warning).

Source: https://keryn.dev/rules/state-transition-integrity-v1/

8 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.statetx.py.copy-without-owner-reapply

`warning` python python

A resource is copied/cloned but the enclosing function sets no owner or ACL on the destination, so the copy inherits default or absent ownership and may be readable by the wrong principal. Re-apply the owner and access control to the destination after copying.

Confidence **P2**: a heuristic or a posture check: confirm by reading the code. False-positive risk **medium**: the pattern is legitimate in many programs, so check each hit.

Edge inspected: [grants](https://keryn.dev/docs/edges/edge-kinds/#grants) authority is given or left unchecked.

[CWE-281](https://keryn.dev/rules/?cwe=CWE-281) [CWE-266](https://keryn.dev/rules/?cwe=CWE-266) [LLM06](https://keryn.dev/taxonomies/owasp-llm/#llm06-excessive-agency) [ASI03](https://keryn.dev/taxonomies/owasp-agentic/#asi03-identity-and-privilege-abuse)

**Fix:** After copying or cloning a resource, set the destination's owner and access control explicitly (chown/chmod/set\_acl, or the application's ownership field) to the authorized principal; do not rely on inherited or default permissions.

**References:** [https://cwe.mitre.org/data/definitions/281.html](https://cwe.mitre.org/data/definitions/281.html) · [https://docs.python.org/3/library/shutil.html#shutil.copy](https://docs.python.org/3/library/shutil.html#shutil.copy)

## keryn.statetx.py.non-atomic-balance-check

`warning` python python

A balance/quota field is compared in a condition and then reassigned by arithmetic on its own value, with no lock or atomic update between. Two concurrent requests both pass the check and both debit (double-spend). Use an atomic conditional update (a single UPDATE ... WHERE balance &gt;= amount, a row lock, or a database transaction).

Confidence **P2**: a heuristic or a posture check: confirm by reading the code. False-positive risk **medium**: the pattern is legitimate in many programs, so check each hit.

Edge inspected: [writes](https://keryn.dev/docs/edges/edge-kinds/#writes) one thing writes to another.

[CWE-367](https://keryn.dev/rules/?cwe=CWE-367) [CWE-362](https://keryn.dev/rules/?cwe=CWE-362) [LLM06](https://keryn.dev/taxonomies/owasp-llm/#llm06-excessive-agency) [ASI02](https://keryn.dev/taxonomies/owasp-agentic/#asi02-tool-misuse-and-exploitation) [ASI08](https://keryn.dev/taxonomies/owasp-agentic/#asi08-cascading-failures)

**Fix:** Make the check and the debit one atomic operation: UPDATE account SET balance = balance - :amt WHERE id = :id AND balance &gt;= :amt and act on the affected row count, or hold a row lock / serializable transaction across the read and the write.

**References:** [https://cwe.mitre.org/data/definitions/367.html](https://cwe.mitre.org/data/definitions/367.html)

## keryn.statetx.py.action-without-replay-guard

`warning` python python, mcp, a2a

An agent/MCP/A2A action handler performs a side effect but its body references no nonce, idempotency key, or replay/once check, so a captured request or message can be replayed. Bind each action to a single-use nonce or idempotency key and reject reuse.

Confidence **P2**: a heuristic or a posture check: confirm by reading the code. False-positive risk **high**: it finds a lead to confirm, so expect benign hits.

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

[CWE-294](https://keryn.dev/rules/?cwe=CWE-294) [CWE-799](https://keryn.dev/rules/?cwe=CWE-799) [LLM06](https://keryn.dev/taxonomies/owasp-llm/#llm06-excessive-agency) [ASI07](https://keryn.dev/taxonomies/owasp-agentic/#asi07-insecure-inter-agent-communication)

**Fix:** Require a single-use nonce or idempotency key on each side-effecting action, record used values, and reject a repeat; do not treat a valid-looking message as fresh by default.

**References:** [https://cwe.mitre.org/data/definitions/294.html](https://cwe.mitre.org/data/definitions/294.html) · [https://modelcontextprotocol.io/docs/2025-11-25/tutorials/security/security_best_practices](https://modelcontextprotocol.io/docs/2025-11-25/tutorials/security/security_best_practices)

## keryn.statetx.ts.copy-without-owner-reapply

`warning` typescript, javascript typescript, nodejs

A resource is copied/cloned but the enclosing function sets no owner or ACL on the destination, so the copy inherits default or absent ownership. Re-apply owner and access control to the destination after copying.

Confidence **P2**: a heuristic or a posture check: confirm by reading the code. False-positive risk **medium**: the pattern is legitimate in many programs, so check each hit.

Edge inspected: [grants](https://keryn.dev/docs/edges/edge-kinds/#grants) authority is given or left unchecked.

[CWE-281](https://keryn.dev/rules/?cwe=CWE-281) [CWE-266](https://keryn.dev/rules/?cwe=CWE-266) [LLM06](https://keryn.dev/taxonomies/owasp-llm/#llm06-excessive-agency) [ASI03](https://keryn.dev/taxonomies/owasp-agentic/#asi03-identity-and-privilege-abuse)

**Fix:** After copying or cloning a resource, set the destination's owner and access control explicitly to the authorized principal; do not rely on inherited or default permissions.

**References:** [https://cwe.mitre.org/data/definitions/281.html](https://cwe.mitre.org/data/definitions/281.html) · [https://nodejs.org/api/fs.html#fspromisescopyfilesrc-dest-mode](https://nodejs.org/api/fs.html#fspromisescopyfilesrc-dest-mode)

## keryn.statetx.ts.non-atomic-balance-check

`warning` typescript, javascript typescript, nodejs

A balance/quota field is compared then reassigned by arithmetic on its own value with no lock or atomic update between, so concurrent requests double-spend. Use an atomic conditional update or a transaction across the read and the write.

Confidence **P2**: a heuristic or a posture check: confirm by reading the code. False-positive risk **medium**: the pattern is legitimate in many programs, so check each hit.

Edge inspected: [writes](https://keryn.dev/docs/edges/edge-kinds/#writes) one thing writes to another.

[CWE-367](https://keryn.dev/rules/?cwe=CWE-367) [CWE-362](https://keryn.dev/rules/?cwe=CWE-362) [LLM06](https://keryn.dev/taxonomies/owasp-llm/#llm06-excessive-agency) [ASI02](https://keryn.dev/taxonomies/owasp-agentic/#asi02-tool-misuse-and-exploitation) [ASI08](https://keryn.dev/taxonomies/owasp-agentic/#asi08-cascading-failures)

**Fix:** Make the check and the debit one atomic operation (a conditional UPDATE guarded by the balance, or a transaction/row lock across read and write).

**References:** [https://cwe.mitre.org/data/definitions/367.html](https://cwe.mitre.org/data/definitions/367.html)

## keryn.statetx.go.non-atomic-balance-check

`warning` go go

A balance/quota field is compared then reassigned by arithmetic on its own value with no lock or atomic update between, so concurrent requests double-spend. Use an atomic conditional update or a transaction across the read and the write.

Confidence **P2**: a heuristic or a posture check: confirm by reading the code. False-positive risk **medium**: the pattern is legitimate in many programs, so check each hit.

Edge inspected: [writes](https://keryn.dev/docs/edges/edge-kinds/#writes) one thing writes to another.

[CWE-367](https://keryn.dev/rules/?cwe=CWE-367) [CWE-362](https://keryn.dev/rules/?cwe=CWE-362) [LLM06](https://keryn.dev/taxonomies/owasp-llm/#llm06-excessive-agency) [ASI02](https://keryn.dev/taxonomies/owasp-agentic/#asi02-tool-misuse-and-exploitation) [ASI08](https://keryn.dev/taxonomies/owasp-agentic/#asi08-cascading-failures)

**Fix:** Make the check and the debit one atomic operation (a conditional UPDATE guarded by the balance, or a transaction/row lock across read and write).

**References:** [https://cwe.mitre.org/data/definitions/367.html](https://cwe.mitre.org/data/definitions/367.html)

## keryn.statetx.go.copy-without-owner-reapply

`warning` go go

A resource is copied/cloned but the enclosing function sets no owner or ACL on the destination, so the copy inherits default or absent ownership. Re-apply owner and access control to the destination after copying.

Confidence **P2**: a heuristic or a posture check: confirm by reading the code. False-positive risk **medium**: the pattern is legitimate in many programs, so check each hit.

Edge inspected: [grants](https://keryn.dev/docs/edges/edge-kinds/#grants) authority is given or left unchecked.

[CWE-281](https://keryn.dev/rules/?cwe=CWE-281) [CWE-266](https://keryn.dev/rules/?cwe=CWE-266) [LLM06](https://keryn.dev/taxonomies/owasp-llm/#llm06-excessive-agency) [ASI03](https://keryn.dev/taxonomies/owasp-agentic/#asi03-identity-and-privilege-abuse)

**Fix:** After copying or cloning a resource, set the destination's owner and access control explicitly (os.Chown/os.Chmod or the application's ownership field).

**References:** [https://cwe.mitre.org/data/definitions/281.html](https://cwe.mitre.org/data/definitions/281.html) · [https://pkg.go.dev/io#Copy](https://pkg.go.dev/io#Copy)

## keryn.statetx.ts.action-without-replay-guard

`warning` typescript, javascript typescript, nodejs, mcp

An MCP/agent tool handler performs a side effect but its argument object destructures no nonce or idempotency key, so a captured request or message can be replayed. Bind each side-effecting action to a single-use nonce or idempotency key and reject reuse.

Confidence **P2**: a heuristic or a posture check: confirm by reading the code. False-positive risk **high**: it finds a lead to confirm, so expect benign hits.

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

[CWE-294](https://keryn.dev/rules/?cwe=CWE-294) [CWE-799](https://keryn.dev/rules/?cwe=CWE-799) [LLM06](https://keryn.dev/taxonomies/owasp-llm/#llm06-excessive-agency) [ASI07](https://keryn.dev/taxonomies/owasp-agentic/#asi07-insecure-inter-agent-communication)

**Fix:** Require a single-use nonce or idempotency key on each side-effecting tool action, record used values, and reject a repeat.

**References:** [https://cwe.mitre.org/data/definitions/294.html](https://cwe.mitre.org/data/definitions/294.html) · [https://modelcontextprotocol.io/docs/2025-11-25/tutorials/security/security_best_practices](https://modelcontextprotocol.io/docs/2025-11-25/tutorials/security/security_best_practices)
