Skip to content

fix(hub): preserve canonical provider keys in audits - #167

Open
alliscode wants to merge 1 commit into
build/hub/newfrom
alliscode-fix-identity-audit-provider-keys
Open

alliscode wants to merge 1 commit into
build/hub/newfrom
alliscode-fix-identity-audit-provider-keys

Conversation

@alliscode

Copy link
Copy Markdown
Collaborator

Why

A provider key accepted by Hub's canonical parser could still be rejected while building a typed security audit when its opaque value resembled credential text, such as secret:workforce. Identity creation and provider revision operations could then roll back, and their terminal failure audit could fail for the same reason. This is a focused follow-up to #163.

What changes

Canonical provider keys now carry a branded type from parseProviderKey() into the audit layer. Typed identity audit events use a narrow provider-key encoder that preserves the exact key for correlation and retains the existing string, byte, entry, and context limits, while bypassing only the generic credential-value heuristic that is inappropriate for this already-validated field. Generic untyped audit context still rejects credential-shaped values, secret-bearing fields, bearer tokens, and private-key material.

Regression coverage exercises representative opaque and Unicode provider keys through the public audit boundary, identity creation and provider revision success, post-rollback failure audits, invalid keys, generic credential rejection, context limits, and raw-error leakage. This changes no provider-key acceptance rules, database schema or migrations, product behavior outside identity auditing, or UI.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI auto review requested due to automatic review settings October 30, 2026 23:00
@alliscode
alliscode requested review from a team and nshki as code owners October 30, 2026 23:00

Copilot AI 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.

🟡 Changes recommended

The oversized fixture never exercises the final byte-limit check, and the new encoder lacks tests confirming rejection of credential-shaped values outside provider.

1 open issue
What changed in this PR

Preserves canonical provider keys in Hub’s identity audits so credential-shaped keys no longer cause identity or provider-revision transactions to roll back. This follows up on the identity transaction foundation in #163.

Changes:

  • Carries a branded provider-key type from parsing into typed audit events.
  • Adds provider-specific context encoding while retaining context limits and generic credential protections.
  • Adds regression coverage for exact key preservation, successful transactions, and post-rollback failure audits.
File Description
hub/​server/​utils/​parse-provider-key/​index.ts Brands validated provider keys without changing acceptance rules.
hub/​server/​utils/​parse-provider-key/​index.test.ts Covers a credential-shaped canonical key.
hub/​server/​repositories/​security-audits/​parse-security-audit-event/​types.ts Defines parsed events with branded provider keys.
hub/​server/​repositories/​security-audits/​parse-security-audit-event/​index.ts Returns the branded event type.
hub/​server/​repositories/​security-audits/​get-security-audit-data/​index.ts Uses provider-specific encoding for identity audits.
hub/​server/​repositories/​security-audits/​create-security-audit/​index.test.ts Checks exact key preservation through the public audit boundary.
hub/​server/​repositories/​security-audits/​create-security-audit-context/​index.ts Adds bounded encoding for canonical provider keys.
hub/​server/​repositories/​security-audits/​create-security-audit-context/​index.test.ts Covers credential rejection and context limits.
hub/​server/​domains/​identity/​validate-and-persist-provider-revision/​index.db.test.ts Exercises provider-key preservation across selection and rollback audits.
hub/​server/​domains/​identity/​resolve-or-create-external-identity/​index.db.test.ts Exercises credential-shaped keys in creation and rollback audits.

Review effort: Max (auto)

Comment on lines +53 to +70

it("retains context bounds for a canonically parsed provider key", () => {
const provider = parseProviderKey("secret:workforce")

expect(() =>
createSecurityAuditContextWithProviderKey({
provider,
first: "界".repeat(500),
second: "界".repeat(500),
third: "界".repeat(500),
fourth: "界".repeat(500),
fifth: "界".repeat(500),
sixth: "界".repeat(500),
seventh: "界".repeat(500),
}),
).toThrow("cannot exceed 4096 bytes")
})
})
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.

2 participants