Skip to content

Audited source and repository ops record no credential - #190

Merged
zlareb1 merged 6 commits into
mainfrom
fix/audit-subject-no-credential
Nov 3, 2026
Merged

zlareb1 merged 6 commits into
mainfrom
fix/audit-subject-no-credential

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in a release)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

The audit rows of tracker.source.add, tracker.source.rotate and code.repo.add no longer hold the tracker password or the repository access token given to the call.

Why

An op with audit=True and no audit_subject records its whole validated input as the audit subject (server/transport/post_rows.py::_audit_subject, input_obj.model_dump(mode="json")). The credential fields of these three ops are plain str, so the dump wrote them in clear text:

  • tracker.source.add: password
  • tracker.source.rotate: password
  • code.repo.add: access_token

loom.audit_log outlives erasure, source removal and repository removal, and is hash-chained, so a credential written there cannot be rotated out of it; the password and token are otherwise only stored sealed (seal/unseal). The audit log must hold no secret.

Each op now declares an audit_subject:

  • tracker.source.add: the input without password, with name and host as stored (from the response).
  • tracker.source.rotate: org, the stored name and the new user.
  • code.repo.add: the input without access_token, plus authenticated (whether a token was given); repo, branch, join_policy, classification and namespace as registered and the extra branches' namespaces (also), all from the response, so a blank branch records the branch it resolved to and a restricted repository records approval.

host_of (server/tracker/domain/sources.py) now drops userinfo: https://u:p@host and tok@host both give host. Before, it returned u for the first and tok@host for the second, so a credential typed into the host field could reach the stored host, the response and the subject; such a host usually failed the host gate, but nothing guaranteed it.

A generic fallback fix (dropping SecretStr fields) would not cover these ops, since their fields are not SecretStr, and changing them to SecretStr changes the wire schema and every handler that reads them. A registry test now fails any audited op whose input has a credential-named field and no audit_subject, so a future op cannot reintroduce the leak through the fallback. A field name is split on _ and matches when a part is password, passwords, passwd, secret, secrets, token, credential, credentials, apikey, authorization, bearer or cookie, or it contains api_key, private_key, signing_key or encryption_key (a bare key is a memory key, not a credential). Exempt: a name ending in _ref (an environment variable's name) and a name with a budget part (token_budget, section_token_budgets: a size in model tokens); *_tokens counters do not match, since tokens is not a part. The test recurses into fields typed as a model (through lists and optionals, stopping at a model already visited); a dict[str, Any] field has no declared keys and is not checked, and the audited ops' dict fields (a tracker mapping, a contract report) hold no credential. On every registered op it finds exactly the three fields above. The other audited ops with secret-like names (webhook.register.secret_ref, inbox.register.webhook_secret_ref) carry the name of an environment variable, not a secret, and are left as they are. code.repo.set_source takes no token and is untouched; code.repo.add_branch inherits the stored token and takes none.

Scope and risk

Touches what the three ops' audit rows record, and host_of, which also normalises the host of sources from the deployment's configuration: a configured host with userinfo now resolves to its hostname instead of a broken value. No wire, storage or auth change. Rows already in loom.audit_log keep what they recorded; this change does not rewrite or delete audit rows (they are hash-chained and sealed into checkpoints), so a deployment that ran these ops should treat any tracker password or repository token registered before this change as exposed to readers of the audit log and rotate it (tracker.source.rotate, or a new token for the repository).

Compatibility, rollout and rollback

  • Wire: none.
  • Rolling upgrade: during the window a build N-1 replica serving one of these ops still writes the whole input, credential included, as its subject; only calls served by build N are clean. Rotate credentials registered during the window as above.
  • Operator steps: none required; rotating credentials registered before the upgrade is recommended.
  • Rollback: reverting brings back the full-input subject; nothing is left behind.

Tests

  • tests/unit/test_audit_subject_credentials.py: one test per op that its subject has no credential key and no credential value, and keeps what an auditor needs (normalised name, stored host, also); one that code.repo.add records the registered branch and join policy for a blank branch and a restricted repository asked as open; one for the matcher's lookalikes and one for a self-referencing model; one test that runs tracker.source.add's real declaration through post_rows.post_handler_rows and checks the subject handed to the audit emit (test_mcp_post_rows.py covers audit_subject only on a stand-in op); one registry test that every audited op with a credential-named input field declares an audit_subject.
  • tests/unit/test_qa_intel_client.py::test_host_drops_userinfo_from_a_url.
  • Every unit test file that imports the tracker sources modules or repo_admin, plus test_public_copy: 367 passed.
  • make format lint typecheck: clean.
  • Full unit suite (pytest tests/unit -p no:randomly) on the first push: 25326 passed, 20 skipped, 1 xfailed.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. Checked: every audited op's input fields against the credential names, the response shapes the subjects read, and that URLs with embedded credentials are refused before an audit row is written (parse_remote).

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand (none affected).
  • A new migration is additive and numbered after the latest on main (none).
  • A behaviour change to any file a plugin ships bumps both plugin manifests' version (none).
  • The frontend builds, if frontend/ changed (unchanged).
  • Docs under docs/ describe the system as it now is (docs/architecture/security.md, Audit log).
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers.
  • Commits are signed off (git commit -s).

🤖 Generated with Claude Code

zlareb1 and others added 6 commits November 3, 2026 09:32
tracker.source.add, tracker.source.rotate and code.repo.add had no
audit_subject, so their audit rows recorded the whole input, the
tracker password and the repository access token included. Each now
declares a subject that leaves the credential out, and a registry test
fails any audited op with a credential-named input field and no
audit_subject.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The tracker subjects take the normalised name and stored host from the
response, the code.repo.add subject adds the extra branches' namespaces,
and host_of strips user:pass@ so a credential typed into the host never
reaches the stored host. The registry test matches credential names by
part, exempts *_ref names, and recurses into nested models; a new test
runs a real op's subject through post_handler_rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The subject takes repo, branch, join_policy and classification from the
response, so a blank branch or a restricted repository asked as open
records what was registered. The registry test matches more credential
names, exempts token budgets, and stops at a self-referencing model.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the fix/audit-subject-no-credential branch from 3ea35b8 to c655701 Compare November 3, 2026 09:35
@zlareb1
zlareb1 merged commit 26a4910 into main Nov 3, 2026
20 of 22 checks passed
@zlareb1
zlareb1 deleted the fix/audit-subject-no-credential branch November 3, 2026 10:04
@pufit pufit mentioned this pull request Nov 4, 2026
9 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant