Repository navigation
fix: hardening across webhooks, session, client, vault, passwordless - #253
Conversation
Wrap sessionId with Uri.EscapeDataString in PasswordlessService.SendSession to match every other generated service path interpolation. Prevents path traversal / URL-injection via malformed session identifiers. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
DecodeLeb128 now caps at 4 continuation bytes and rejects truncated prefixes. DecryptAsync validates that the decoded key length fits in the remaining buffer before allocating, preventing pathological inputs from triggering ~4 GB allocations. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Move auto-generation of the Idempotency-Key GUID out of CreateHttpRequestMessage (which runs once per attempt) and into MakeRawAPIRequest before the retry loop. All retries for a given request now send the same key, so server-side dedup actually works and a duplicate write cannot slip through on a retried POST. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ValidateJwt now sets ValidateIssuer, ValidateAudience, and ValidAlgorithms
on TokenValidationParameters. Defaults derive from the configured client
({ApiBaseURL}/user_management/{clientId} as the issuer; clientId as the
audience; RS256 as the only accepted algorithm). Each of these is
overridable via additive optional properties (ValidIssuer, ValidAudience,
ValidAlgorithms) on SessionService so existing callers keep working — no
required-parameter break.
Leaves a TODO comment on the literal documented WorkOS issuer/audience
strings.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
GetTimestampAndSignature now validates that the signature header splits into exactly two comma-separated parts before indexing, preventing an IndexOutOfRangeException on malformed input. VerifyTimeTolerance wraps long.Parse and the UnixTimeToDateTime / AddMilliseconds path in try/catch and re-raises as WorkOSWebhookException so callers see a single, expected exception type for malformed timestamps. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Replace the one-sided "now - timestamp > tolerance" comparison with Math.Abs(nowMs - timestampMs) > tolerance * 1000L so a far-future timestamp is rejected the same way a too-old one is. Matches the ActionsService.VerifyHeader pattern. The unused UnixTimeToDateTime helper is removed in the same change. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Greptile SummaryThis PR applies targeted security hardening across six components — webhooks, session JWT validation, HTTP client retries, vault decryption, and passwordless URL construction — all of which had exploitable edge cases. The algorithm / lifetime hardening in
Confidence Score: 4/5Safe to merge for the vault, client, passwordless, and webhook hardening; the session service ships with issuer and audience validation deliberately disabled by default, an open item acknowledged in the PR description that existing review threads have flagged. The vault, webhook, idempotency, and URL-encoding changes are straightforward and correct. The session service intentionally leaves iss/aud enforcement opt-in pending confirmation of WorkOS canonical claim values — a deliberate deferral that existing review threads already track. Until that gap is closed, the JWT validation is incomplete relative to the team's stated rule that both claims must always be validated. src/WorkOS.net/Services/Session/SessionService.cs — the opt-in issuer/audience validation leaves a security gap that should be resolved before treating the session hardening as complete. Important Files Changed
|
…eader GetTimestampAndSignature now raises WorkOSWebhookException for null, wrong-arity, and missing-prefix headers instead of ArgumentException. This keeps the verification path exception contract consistent with VerifyTimeTolerance, so callers catching WorkOSWebhookException on VerifyHeader cover every malformed-input case. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Issuer validation is now opt-in via SessionService.ValidIssuer rather
than defaulting to the unverified {ApiBaseURL}/user_management/{clientId}
string. Shipping that derived issuer turned ValidateIssuer = true on by
default against a value that has not been confirmed against real WorkOS
access tokens, which would have rejected every legitimate token after
upgrade. Until the literal issuer string is verified, callers who want
issuer enforcement set it explicitly.
Audience validation no longer silently disables when ClientId is empty:
if neither ValidAudience nor ClientId is set, ValidateJwt now throws
InvalidOperationException instead of skipping the check.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Aligns the malformed-header assertion with the exception type now raised by GetTimestampAndSignature. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Defaulting ValidAudience to ClientId would reject every legitimate token on upgrade if WorkOS access tokens carry a different `aud` (e.g. a resource-server URL rather than the client identifier). The workos-php investigation under workos/workos-php#386 confirmed that the canonical WorkOS `iss` / `aud` values are not documented across SDKs — workos-node validates only signature + algorithm + expiry, and Ruby/Python skip `aud` entirely. Audience now mirrors issuer: validated only when ValidAudience is explicitly configured. Signature, algorithm, and lifetime remain enforced unconditionally. Once the canonical claim values are confirmed, defaults can be reintroduced safely. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
An empty IList<string> bypassed the ?? null-coalescing fallback, leaving the JWT handler with an empty algorithm list — which some Microsoft.IdentityModel.Tokens runtimes interpret as "accept any algorithm" rather than rejecting. Default to RS256 when the list is null OR empty. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Description
Summary
IndexOutOfRangeExceptionon malformed input; malformed headers and timestamp parse errors surface asWorkOSWebhookException; timestamp tolerance check is symmetric (Math.Abs(...)) so far-future timestamps are rejected like too-old ones, matchingActionsService.VerifyHeader.ValidateJwtnow enforces token lifetime and accepted signing algorithms, defaulting toRS256. Issuer and audience validation are available through additive optionalValidIssuer/ValidAudienceproperties, but remain opt-in until the canonical WorkOS claim values are confirmed.MakeRawAPIRequestbefore the retry loop instead of per-attempt inCreateHttpRequestMessage, so retried POSTs reuse the same key and server-side dedup actually works.DecodeLeb128is bounded to 4 continuation bytes and rejects truncated prefixes;DecryptAsyncvalidates the decoded key length fits the remaining buffer before allocating, preventing ~4 GB allocations from pathological inputs.sessionIdis wrapped withUri.EscapeDataStringinSendSession, matching every other generated service path and blocking path traversal / URL injection.Reviewer notes
iss/audenforcement.Test plan
WorkOSWebhookExceptionValidIssuer/ValidAudience/ValidAlgorithmsoverrides work as expectedIdempotency-Keyon every attemptSendSessionwith a sessionId containing reserved URL chars hits the correctly-escaped pathDocumentation
Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.
Link to Devin session: https://app.devin.ai/sessions/eb5c055e7c324404990419c4a8f6f26d
Requested by: @gjtorikian