Skip to content

fix(data_flow,propagation): validate endpoints and size/token bounds, reject control chars and conflicting headers in Python and TypeScript (#104) - #108

Merged
rajnisht7 merged 3 commits into
agentrust-io:mainfrom
drk-ram:drk-ram-fix-data-flow-propagation-103
Nov 25, 2026
Merged

rajnisht7 merged 3 commits into
agentrust-io:mainfrom
drk-ram:drk-ram-fix-data-flow-propagation-103

Conversation

@drk-ram

@drk-ram drk-ram commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Python classified_data_flow (src/agentrust_telemetry/data_flow.py) validates isinstance(source, DataEndpoint), isinstance(destination, DataEndpoint), and non-negative safe-integer size_bytes and token_count (rejecting bool) to match TypeScript classifiedDataFlow.
  • Python propagation.py rejects ASCII control characters (\x00..\x1f, \x7f) and conflicting case-insensitive duplicate correlation headers.
  • TypeScript propagation.ts gets the same two guards for injectContext / extractContext. Identical case-insensitive duplicates are still accepted, as in Python. Before this, TS accepted control characters and silently used the first of two conflicting headers.
  • classified_data_flow and classifiedDataFlow check source and destination before they call the caller's classifier, so a malformed endpoint no longer runs it. TS had no explicit check and failed later on a missing asEventValue.
  • Tests cover inject_context / extract_context directly in Python (previously only _safe_value / _header). TS tests cover control characters, conflicting vs identical duplicates, the 512-character limit and an undefined header value. Both languages assert that a bad endpoint raises before the classifier is called, each with a valid twin.
  • CHANGELOG.md and docs/architecture.md describe the header rules.

Closes #104

Contract impact

  • No wire-contract change
  • Backward-compatible contract change with fixtures
  • Breaking contract change with migration notes

Evidence

Python 3.11, Node 26, Windows.

  • python tools/sync_schemas.py: no output, no diff.
  • python tools/check_schemas.py: PASS, 8 bundled schemas match normative bytes.
  • python conformance/runner/validate.py: PASS.
  • python -m unittest discover -s tests -v: 203 tests OK (2 skipped).
  • python -m build: sdist and wheel built.

Also run: tools/check_workflow_oidc.py, check_versions.py, check_otel_compatibility.py and check_typescript_schemas.py (all PASS); npm run check in packages/typescript (build, 87 tests, npm pack --dry-run) passed; git diff origin/main...HEAD --check is clean.

ruff check on the four changed Python files reports the same 9 findings as before this change, none on changed lines. mypy src reports the same 6 existing errors, none in data_flow.py or propagation.py.

Patch coverage (coverage run --branch for Python, Node's test coverage for TS): every changed line in data_flow.py, propagation.py, data-flow.ts and propagation.ts is executed, with no uncovered branch on a changed line. Removing the TS control-character guard, the TS duplicate check, the undefined filter, or the endpoint check-before-classify (TS or Python) fails the new tests.

Privacy and security

  • No real prompts, source, credentials, personal data, or production identifiers added
  • New fields have capture semantics and privacy classification (no new fields)
  • Security-sensitive changes received maintainer review (pending a re-review of this head)

Limits

This adds input validation only; the wire contract is unchanged. It does not stop a caller from setting a header on the carrier directly, and it does not address duplicate traceparent headers.

@drk-ram
drk-ram requested review from a team and imran-siddique as code owners October 23, 2026 22:59
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

🟡 Contributor Check: MEDIUM

Check Result
Profile MEDIUM
Credential LOW
Overall MEDIUM

Automated check by AgenTrust Contributor Check.

@github-actions github-actions Bot added the needs-review:MEDIUM Contributor check flagged MEDIUM risk label Oct 23, 2026
@drk-ram
drk-ram force-pushed the drk-ram-fix-data-flow-propagation-103 branch from 50a97ec to 4504aef Compare October 23, 2026 22:59

@dinakarjs dinakarjs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed source at 4504aef. Python unittest discovery passed with inherited OTEL_* variables removed; the initial three OTel failures were environment configuration. TypeScript build and all 44 existing tests passed using node --import tsx --test test/*.test.ts; the npm check launcher itself encountered an IPC-listen EPERM here, so I do not claim that wrapper passed. Local results only, not hosted CI. Python: 159 tests pass.

The new combined test stops on its first failing size assertion, so it does not independently demonstrate the control-character and conflicting-header guards. Please split the regression into independent tests and add valid twins, including identical case-insensitive duplicate headers and boundary size values. Also correct the description's closing reference: data-flow/propagation is #104, not #103.

Source review and local validation are complete within this scope; regression coverage remains for author follow-up before approval.

Prepared with OpenAI Codex.

@drk-ram drk-ram changed the title fix(data_flow,propagation): validate size_bytes/token_count in Python data_flow and reject control chars and conflicting headers in propagation (#103) fix(data_flow,propagation): validate size_bytes/token_count in Python data_flow and reject control chars and conflicting headers in propagation (#104) Oct 24, 2026
@drk-ram

drk-ram commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @dinakarjs! Split the regression into three independent test methods in tests/test_data_flow.py (test_data_flow_validates_endpoints_and_safe_integer_size_and_token_bounds, test_propagation_rejects_control_characters, and test_propagation_rejects_conflicting_duplicate_headers_and_accepts_identical_duplicates) with valid boundary twins (0 and 2**53 - 1, plus identical case-insensitive duplicate headers), and updated the PR title/description to Closes #104.

@dinakarjs dinakarjs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed exact head a353e79. The independent data-flow, control-character, and conflicting-header tests address my failure-isolation request, retain valid boundaries and identical-header controls, and the issue reference is corrected to #104. Local Python suite: 161 passed; TypeScript build and all 44 tests pass using node --import tsx --test test/*.test.ts. Independently removing the control-character guard or the conflicting-header guard makes the corresponding committed assertions fail. No source edits retained. This is bounded source/test approval; hosted checks remain separate. Broad optional Ruff reports findings, so this does not claim repository-wide lint cleanliness. Reviewed with OpenAI Codex.

@drk-ram
drk-ram force-pushed the drk-ram-fix-data-flow-propagation-103 branch from a353e79 to cec2a3f Compare November 13, 2026 01:12
imran-siddique
imran-siddique previously approved these changes Nov 15, 2026

@imran-siddique imran-siddique left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving at cec2a3f: ran conformance, the Python suite and the TS check on this head; each new test fails against main's source; all 11 PRs in this series merge onto main together without conflicts and pass combined.

@rajnisht7 rajnisht7 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things:

  • Issue #104 asks for the control-character and conflicting case-insensitive header checks in both Python and TypeScript. Python does this now, but packages/typescript/src/propagation.ts still accepts control chars (\x00–\x1f, \x7f) and silently picks one value when there are conflicting case-insensitive duplicates on the run/workflow/agent headers, kindly add the same guard and test there
  • the new Python tests only hit _safe_value / _header. Worth also covering inject_context / extract_context so the public API is locked in.
  • classified_data_flow still calls the classifier before checking that source / destination are DataEndpoints, so a bad endpoint still runs the user classifier. Moving those checks first would be a small improvement (same pattern exists in TS).

… data_flow and reject control chars and conflicting headers in propagation (agentrust-io#104)


- Validate DataEndpoint types and non-negative safe-integer size_bytes and token_count in Python classified_data_flow, matching TypeScript classifiedDataFlow.
- Reject ASCII control characters and conflicting case-insensitive duplicate headers in Python propagation.

Closes agentrust-io#104

Signed-off-by: Raghuvar Karthik Durga <177662415+drk-ram@users.noreply.github.com>
… twins


Signed-off-by: Raghuvar Karthik Durga <177662415+drk-ram@users.noreply.github.com>
… Python and check endpoints before classifying (agentrust-io#104)

- TypeScript injectContext/extractContext reject ASCII control characters
  (U+0000-U+001F, U+007F) in the AgenTrust header values, and extractContext
  rejects case-insensitive duplicates of the run, workflow and agent headers
  that carry different values. Identical duplicates are still accepted, as in
  Python. It used to take the first header it found.
- classified_data_flow and classifiedDataFlow check that source and
  destination are DataEndpoints before calling the caller's classifier, so a
  malformed endpoint no longer runs it. TypeScript had no such check and
  failed later with a missing asEventValue.
- Cover inject_context and extract_context directly in Python, and the
  control-character, duplicate-header, length and endpoint-ordering cases in
  both languages, each with a valid twin.

Signed-off-by: Raghuvar Karthik Durga <177662415+drk-ram@users.noreply.github.com>
@drk-ram
drk-ram force-pushed the drk-ram-fix-data-flow-propagation-103 branch from c24d169 to 6718497 Compare November 25, 2026 17:03
@drk-ram drk-ram changed the title fix(data_flow,propagation): validate size_bytes/token_count in Python data_flow and reject control chars and conflicting headers in propagation (#104) fix(data_flow,propagation): validate endpoints and size/token bounds, reject control chars and conflicting headers in Python and TypeScript (#104) Nov 25, 2026
@drk-ram

drk-ram commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@rajnisht7 thanks, all three are in at 6718497, rebased onto current main (it had drifted past #110, #116, #118, #119 and #120).

  • TypeScript propagation: safe in propagation.ts now rejects [\x00-\x1f\x7f] for injectContext and extractContext, and extractContext rejects case-insensitive duplicates of the run, workflow and agent headers that carry different values. Identical duplicates are accepted, matching Python. It used to take the first header it found. Tests cover each header with \x00, \x1f, \x7f, \t and \x0b, space and ~ as valid twins on either side of the range, conflicting vs identical duplicates, a bad value hiding behind an identical twin, and the 512-character boundary. That last one wasn't covered in either language, so I added it in both.
  • Public API in Python: inject_context / extract_context are now covered directly for control characters in every field, conflicting vs identical duplicates, empty and non-string values, and the length limit. The existing _safe_value / _header tests stay.
  • Classifier ordering: classified_data_flow and classifiedDataFlow check source and destination before they call the classifier. The tests use a counting classifier: a bad source or destination raises TypeError and the classifier is never called, while the same call with real endpoints calls it once. In TS there was no explicit check at all, only a missing asEventValue after classification, so it now throws the same TypeError as Python.

I also added a CHANGELOG entry and a line in docs/architecture.md. Python unittest discover is 203 tests OK, npm run check in packages/typescript passes (87 tests), check_schemas, conformance/runner/validate.py and python -m build are clean, and git diff origin/main...HEAD --check is clean. Every changed line in the four source files is covered, branches included, and removing each new guard in turn fails the new tests. ruff and mypy report the same findings as before on these files, none on changed lines.

@rajnisht7
rajnisht7 enabled auto-merge (squash) November 25, 2026 20:02

@rajnisht7 rajnisht7 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the update, the previous findings are addressed.
one thing (can be followed up): Python and TypeScript disagree on the meaning of the 512-character limit for supplementary Unicode characters

@rajnisht7
rajnisht7 merged commit 2d28ee6 into agentrust-io:main Nov 25, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-review:MEDIUM Contributor check flagged MEDIUM risk

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(data_flow,propagation): validate size_bytes/token_count in Python data_flow and reject control chars and conflicting headers in propagation

4 participants