Skip to content

Harden the trace exporter's file and endpoint handling - #656

Open
sabasiddique1 wants to merge 2 commits into
GenAI-Security-Project:integrationfrom
sabasiddique1:refimpl/otel-file-endpoint-283
Open

sabasiddique1 wants to merge 2 commits into
GenAI-Security-Project:integrationfrom
sabasiddique1:refimpl/otel-file-endpoint-283

Conversation

@sabasiddique1

@sabasiddique1 sabasiddique1 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

What changed

The trace file was opened by path with no checks, so a symlink or another user's file could receive trace content, and plain http:// could carry spans to another host unencrypted. The file output now opens with O_WRONLY|O_APPEND|O_CREAT|O_NOFOLLOW|O_NONBLOCK on every append, checks the descriptor and the parent directory, and sets the mode to 0600. Plain http:// to a host that is not loopback builds no endpoint output unless ACS_OTEL_ALLOW_PLAINTEXT_ENDPOINT=1 is set. A step still open at shutdown past its timeout now gets class timeout, and elapsed_ms rounds up, so a late decision never shows the timeout value. An error code past the safe integer range is clamped to the bound, and one too large for a number is no longer dropped.

Scope

Item by item against #283:

  1. File opens. Done. It refuses a symlink at the path, a symlink as the parent directory, a second hard link, a file that is not regular, a file or directory another user owns, and a world-writable parent directory. A wider mode is tightened to 0600, not refused. Only the immediate parent directory is checked, and by name. The checks run at each append, so a refused path first shows with the first batch. Windows is a documented branch that protects less: it checks no owner, refuses no world-writable directory, and sets no mode. Its tests run through a platform option.
  2. Non-loopback http://. Done. No endpoint output without the opt-in, a warning with it, and a refusal with it when OTEL_EXPORTER_OTLP_HEADERS or OTEL_EXPORTER_OTLP_TRACES_HEADERS is set. Loopback is read from the parsed address: 127.0.0.0/8, ::1, and the IPv4-mapped form. The exporter reads those two headers variables from process.env itself, because that is where the SDK reads them. It read no environment before. The Guardian README documents TLS and headers.
  3. Steps open at shutdown. Done. A step open for longer than its timeout gets class timeout. Otherwise it stays other.
  4. elapsed_ms. Done. It is rounded up, so it never equals timeout_ms on a late decision.
  5. Error codes. Done. PR fix(guardian): read failure event and step attributes from otel-mapping.json and harden audit-to-otlp #349 closed without merging, so asClampedErrorCode is added here, as rocklambros wrote it in his review of that PR. It clamps a code to the safe integer bounds, turns NaN into no code, and keeps a fraction, so -32005.5 stays on the step and is not read as a rejection. The exporter uses it. Tests cover -1e21, 1e21 and a 400-digit code, which clamp to the bound, -32005.5, which stays the same, and an exporter span with -1e21, which carries the bound.
  6. Spans the Guardian cannot vouch for. The source landed in PR Record a request the Guardian cannot vouch for apart from the steps, never under its claimed ids #309. This PR adds only the acceptance test. The premortem's four re-posts aren't listed on the issue, so the test uses four that fail the schema in different ways: no JSON-RPC id, no timestamp, a version that is not semver, and a payload with no arguments. A re-post that passes the schema still lands under the real pair, a known limit in the tree README.
  7. Signal path in main.ts. Not here. It waits for PR Batch Guardian log writes and drain them on shutdown #112.

Three things go past the letter of the issue:

  • A user name or password in the endpoint URL is refused under the opt-in, for the same reason as the headers.
  • The proxy helpers now cover every address the loopback rule accepts, http://127.0.0.2 included.
  • The converter checks its output directory before it creates the file, so a refused directory is left empty. It changes 4 lines in audit-to-otlp.ts.

This PR and my PR #655 for #282 change the same shutdown lines, the Guardian README, the test file and the Go recording. I'll rebase whichever lands second.

Credit

Thanks to rocklambros for the clamp and its tests, from his review of PR #349, and to drk-ram for the first version of it in that PR. Thanks also to bar-capsule for the ruling on item 6, and to rocklambros for PR #309.

Questions for the reviewer

@rocklambros, two questions:

  1. localhost is the one name that counts as loopback. Should it, or should it need the opt-in?
  2. A parent directory its group can write to is accepted, and only a world-writable one is refused. Do you want group-writable refused too?

Which issue does this implement

Part of #283
Refs #274

  • This is an editorial correction (typo, grammar, link, formatting) with no change in
    meaning, so it needs no issue

Base branch

  • integration, because this touches the specification, schemas, a reference
    implementation, an adapter, tests, or CI
  • main, because every changed path is on the documentation lane allowlist in
    CONTRIBUTING.md

Type of change

  • Specification change (schema, hooks, events, AgBOM)
  • Reference implementation or adapter
  • Documentation
  • Tooling or CI
  • Governance (licensing, security policy, contributor docs)

I tested this

  • I synced my branch with the base branch before opening this
  • uv run pytest -v passes on my machine
  • uv run mkdocs build --strict passes on my machine

How I tested

From reference-implementations/agt, on Bun 1.3.11 and again on Bun 1.3.14:

bun run typecheck
bun test
  • Typecheck is clean.
  • Bun 1.3.11: 1340 pass, 4 skip, 0 fail.
  • Bun 1.3.14: 1343 pass, 1 skip, 0 fail.
  • The three changed test files passed three runs in a row on each version.

From the repo root, uv run pytest -v gives 1258 passed and 1 skipped, and uv run mkdocs build --strict passes. Each new test goes red when the code it covers is broken.

The second commit re-records the Go Guardian's TypeScript cases, because the Guardian source changed. From reference-implementations/agt-go I ran ./scripts/record-ts-cases.sh with Go 1.27.4. Only the packages/guardian/src tree id changed. The 49 recorded answers are the same. go test ./... passes.

I ran this on macOS only. CI is its first Linux run, and the Windows branch ran only through the platform option.

Checklist

  • Commits are signed off with git commit -s (required by the DCO)
  • Prose follows STYLE.md
  • No secrets, tokens, or internal URLs in the diff

Security

  • This change has no security impact

This is a hardening change. It refuses paths and endpoints that worked before:

  • a trace file that is a symlink, has a second hard link, or is not a regular file;
  • a trace file in a world-writable directory such as /tmp, or in a directory that is a symlink;
  • a file or directory another user owns;
  • plain http to a host that is not loopback, without the opt-in.

An existing trace file with a wider mode is changed to 0600.

@github-project-automation github-project-automation Bot moved this to Needs triage in ACS Project Tracker Nov 20, 2026
bar-capsule pushed a commit that referenced this pull request Nov 24, 2026
## What changed

Item 6 of #284 asks for tests that were missing, so a wrong attribute or
a wrong path fails a test. This adds them, and gives the slow converter
test a 30 s timeout. No file under `src` changes.

### Scope

Against item 6 of #284:

- **The "empty array is absent" rule.** Done.
- **The off-by-default test, able to fail.** Done. It catches a default
in the factory, and a relative default path in `startGuardian`. It
misses a default endpoint or an absolute path there, because neither
writes into the listed directory.
- **End-to-end join test.** Done. Both files record the same step, a
late decision. The Guardian's bridge is the real deployment bridge, held
back until the host has timed out.
- **Converter posture and parsing paths.** Done, in five tests.
- **Slow converter test.** Done, with `30_000` as the third argument. It
can't fail first here, because that test takes about half a second on my
machine.
- **`acs.exit_status`.** No work. `test/sample-trace.test.ts` already
catches a wrong field, as rocklambros said on the issue.

Items 1 to 5 and 7 of #284 are not here. rocklambros split the issue on
2026-10-31: item 6 here, the rest in PR #349. The fix to the test `emits
the decision extras whether the mapping lists them or not` is in PR #349
too.

### Credit

PR #349 is drk-ram's. The list of what each test should check is
rocklambros's, from Ask 6 of his review of it.

### Questions for the reviewer

@bar-capsule, no questions, one thing to know. This has merge conflicts
with PR #349 in `test/audit-to-otlp.test.ts`: the imports, the
`OtlpSpan` type, and the end of the file. Taking the union resolves it.
I'll rebase if #349 merges first. It also conflicts with my PR #656 for
#283 in `otel-trace-exporter.test.ts`, and I'll rebase mine there too.

## Which issue does this implement

Part of #284
Refs #274

- [ ] This is an editorial correction (typo, grammar, link, formatting)
with no change in
      meaning, so it needs no issue

## Base branch

- [x] `integration`, because this touches the specification, schemas, a
reference
      implementation, an adapter, tests, or CI
- [ ] `main`, because every changed path is on the documentation lane
allowlist in
      CONTRIBUTING.md

## Type of change

- [ ] Specification change (schema, hooks, events, AgBOM)
- [x] Reference implementation or adapter
- [ ] Documentation
- [ ] Tooling or CI
- [ ] Governance (licensing, security policy, contributor docs)

## I tested this

- [x] I synced my branch with the base branch before opening this
- [x] `uv run pytest -v` passes on my machine
- [x] `uv run mkdocs build --strict` passes on my machine

### How I tested

From `reference-implementations/agt`, on Bun 1.3.11 and again on Bun
1.3.14:

```bash
bun run typecheck
bun test
```

- Typecheck is clean.
- Bun 1.3.11: 1302 pass, 4 skip, 0 fail.
- Bun 1.3.14: 1305 pass, 1 skip, 0 fail.
- The two changed test files passed three runs in a row on each version.

From the repo root, `uv run pytest -v` gives 1251 passed and 1 skipped,
and `uv run mkdocs build --strict` passes. Each new or rewritten test
goes red when the source it covers is broken. All of them also pass on
top of PR #349 merged with `integration`.

I ran this on macOS only.

## Checklist

- [x] Commits are signed off with `git commit -s` (required by the DCO)
- [x] Prose follows [STYLE.md](../STYLE.md)
- [x] No secrets, tokens, or internal URLs in the diff

## Security

- [x] This change has no security impact

Signed-off-by: Saba Siddique <sabasiddiqdev@gmail.com>
@sabasiddique1
sabasiddique1 force-pushed the refimpl/otel-file-endpoint-283 branch from 9644474 to f9ac0a0 Compare November 25, 2026 18:16
Part of GenAI-Security-Project#283
Refs GenAI-Security-Project#274

Signed-off-by: Saba Siddique <sabasiddiqdev@gmail.com>
Signed-off-by: Saba Siddique <sabasiddiqdev@gmail.com>
@DanPazlev

Copy link
Copy Markdown
Collaborator

It looks like #656 and #655 both change trace exporter output handling. Think we can agree for the merge order and make sure #655's dropped-span count survives #656's changes. Thoughts?

@DanPazlev

Copy link
Copy Markdown
Collaborator

In review, I see there's conflicts:

I don't see that this branch merges cleanly into integration (ts-cases.json under agt-go/agtbridge/testdata). It also conflicts with #655 in the guardian trace exporter source, its test, and the README. Please rebase onto integration first, then resolve the overlap with #655. Suggest #655 lands first, and this branch rebases on it. Happy to re-review once pushed.

@DanPazlev

Copy link
Copy Markdown
Collaborator

Governance: this links only #274, which is assigned to Rock. Please open or link the issue this PR implements (or confirm #274 is the right one) and assign it to yourself so it passes the intake check.

@acs-board-reconciler acs-board-reconciler Bot moved this from Needs triage to In progress in ACS Project Tracker Dec 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

2 participants