Skip to content

Internal refactors: error-leak scrubbing, session accessors, OCSF drift fix - #30

Open
bryanegan wants to merge 2 commits into
mainfrom
chore-internal-refactors
Open

Internal refactors: error-leak scrubbing, session accessors, OCSF drift fix#30
bryanegan wants to merge 2 commits into
mainfrom
chore-internal-refactors

Conversation

@bryanegan

Copy link
Copy Markdown
Contributor

Deferred design-review improvements. All internal — no wire or behavior change except two deliberate tightenings (noted below).

Security / correctness

  • #33 Error leaksInternal and TokenExchangeFailed now log detail via tracing::error! and return a fixed generic body; the raw text could carry pool ids, client ids, ARNs. RefreshFailed deliberately keeps its message (describes the caller's own token state; auth.js surfaces it) — the contract is now explicit in comments instead of accidental. This is a response-body change for two 500-class errors.
  • #36 OCSF drift (real bug found)logout.rs had an inline copy of the auth-protocol mapping that reported auth_method: "password" as OAuth 2.0/OIDC. Every logoff event for password users has been carrying wrong data into whatever SIEM consumes it. Now uses the shared (correct) helper.

Test-quality

  • error.rs tests re-implemented the status/body mapping — so the leak-scrubbing above would not have been caught. Rewritten to exercise the real into_response, plus two leak-assertion tests.
  • ocsf.rs had no tests at all. Added a module pinning the (id, name) pairs as a wire contract + a regression guard for the exact drift.

Cleanup (pure internal)

  • #35 SessionHandle gains tokens()/tokens_opt()/set_tokens()/destroy(), replacing the same stringly-typed 5-line block pasted across 6 handlers and 5 duplicated destroy sites. A malformed tokens value now logs WARN (corrupt session) instead of being silently indistinguishable from logged-out.
  • #38 Removed the ignored _context param from CedarState::authorize; documented on the wire type why context is accepted-but-ignored (S5).
  • #49 SessionLayer<B> was only ever SessionLayer<AnyBackend> — concretized.

189 Rust tests (was 179), clippy clean.

🤖 Generated with Claude Code

bryanegan and others added 2 commits July 31, 2026 17:49
…aram cleanup

Deferred design-review improvements. All internal — no wire/behavior change
except the deliberate error-body tightening.

- #33 AppError leaks: Internal and TokenExchangeFailed now log their detail via
  tracing::error! and return a fixed generic body; the raw text could carry pool
  ids, client ids, ARNs. RefreshFailed deliberately KEEPS its message (it
  describes the caller's own token state and auth.js surfaces it) — the contract
  is now explicit in comments rather than accidental.
  Also rewrote error.rs tests to exercise the REAL into_response (they had
  re-implemented the mapping, so the scrubbing would not have been caught) and
  added two leak-assertion tests.
- #35 Session accessors: SessionHandle gains tokens()/tokens_opt()/set_tokens()/
  destroy(), replacing the same 5-line stringly-typed incantation pasted across
  6 handlers + 5 duplicated destroy sites in callback.rs. A malformed `tokens`
  value now logs WARN (corrupt session) instead of being silently indistinct
  from logged-out.
- #38 Dead param: removed the ignored `_context` from CedarState::authorize;
  documented on AuthorizeRequest.context why the wire field is accepted-but-
  ignored (S5) rather than leaving it unexplained.
- #49 Vestigial generic: SessionLayer<B> was only ever SessionLayer<AnyBackend>;
  concretized to Arc<AnyBackend> and dropped the generic from session_middleware.

185 Rust tests pass (was 179), clippy clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The design review flagged the 8-positional-arg OCSF API as drift-inviting and
noted the drift had already happened. Confirmed: logout.rs carried an inline
copy of the auth-protocol mapping that reported `auth_method: "password"` as
AUTH_PROTOCOL_OAUTH2 / "OAuth 2.0/OIDC" — wrong data in every logoff event for
password users, silently, in whatever SIEM consumes these.

- logout.rs now calls the shared ocsf::auth_protocol_from_method() (which was
  already correct and already used by session.rs).
- ocsf.rs had NO tests at all; added a module pinning the (id, name) pairs as a
  wire contract, a regression guard asserting password != OAuth2, severity/status
  name coverage, and an emit()-never-panics check.

Chose the shared-helper fix over the review's enum/struct redesign: it removes
the drift at its source with no call-site churn across 20+ event emissions.
The enum refactor stays available if the arg list grows again.

189 Rust tests pass, clippy clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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