Skip to content

fix: preserve encrypted response fallback with multiple certificates - #1150

Merged
deepakprabhakara merged 2 commits into
ory:mainfrom
srkirkland:srk/encrypted-response-certificate-rollover
Nov 22, 2026
Merged

deepakprabhakara merged 2 commits into
ory:mainfrom
srkirkland:srk/encrypted-response-certificate-rollover

Conversation

@srkirkland

@srkirkland srkirkland commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Valid responses containing an encrypted Assertion inside a signed Response are rejected when publicKey contains multiple comma-separated certificates, including a duplicate of the same certificate. The same response succeeds with a single certificate. This affects identity providers publishing multiple signing certificates during rollover.

Decryption changes the signed Response's digest, so validation must retry against the original encrypted XML. The multi-certificate path currently throws when checkSignature() returns false, preventing that existing fallback. Preserve the false result, matching the single-certificate path, while retaining the error when every certificate attempt throws. Successful validation still requires a verified signature over the original XML; signature and claim checks remain in place.

The regression tests use existing synthetic fixtures and cover the active certificate first, active certificate last, and duplicate certificates. Each configuration must accept the valid response and reject tampering, an incorrect audience, and an incorrect request ID. A separate case rejects an entirely untrusted certificate list.

Validation: all three new acceptance cases fail on unmodified main and pass with the fix. All 1,718 tests pass on Node 24, along with lint, formatting, build, and type checks. An equivalent fix has also been validated in a downstream Jackson deployment with real federated sign-ins.

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation of encrypted SAML responses when multiple trusted certificates are configured, including lists with the trusted certificate first or last or appearing more than once.
    • Valid responses can now be validated consistently with single-certificate configurations. Tampered responses, responses with an incorrect audience or request correlation, and responses signed only by untrusted certificates continue to be rejected.

@CLAassistant

CLAassistant commented Nov 16, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Multi-certificate signature verification now throws only when the verification result is undefined. A false result can reach the null return path. Tests cover encrypted Responses with varied certificate lists, tampering, audience and request-correlation checks, and untrusted certificates.

Changes: Response signature validation

Layer / File(s) Summary
Verification result handling and Response coverage
lib/validateSignature.ts, test/lib/response.spec.ts, test/lib/validateSignature.spec.ts
The multi-certificate branch throws when verification returns undefined, rather than for any falsy result. Tests cover trusted certificate order and duplicates, tampered responses, audience and request-correlation checks, untrusted certificates, and a digest-mismatch error.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: niwsa, deepakprabhakara, pi1814

Merge Risk: Minimal · up to 9226f

This change lets valid signed SAML Responses with encrypted assertions be accepted when several signing certificates are configured, such as during certificate rollover. Signature and claim checks remain in place, and the tests cover the accepted and rejected cases. No merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: the encrypted response fallback is preserved when the publicKey setting holds multiple certificates. The summary and objectives describe the same fix to the multi-cert…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the encrypted response fallback is preserved when the publicKey setting holds multiple certificates. The summary and objectives describe the same fix to the multi-certificate branch of hasValidSignature, which now throws only when valid is undefined, so a false result allows the retry against the original encrypted XML. The title is specific, uses a conventional prefix, and matches the changeset.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 375fb76a-62e6-4150-aef6-702e3211e65e
Commits

Reviewing files that changed from the base of the PR and between 129091d and 9226fcf.

Files selected for processing: 3

  • lib/validateSignature.ts
  • test/lib/response.spec.ts
  • test/lib/validateSignature.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Assert the specific rejection for a tampered Response and an untrusted
certificate list, and cover a digest mismatch with multiple certificates
directly in validateSignature. Write the check as `valid === undefined`.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EdsD5LceNhxMXQTQv7x1Dt
@deepakprabhakara

Copy link
Copy Markdown
Collaborator

Thanks for the fix and the clear write-up, @srkirkland. The diagnosis is spot on: xml-crypto checks the reference digests before it looks at any key, so the multi-certificate path was throwing before the encrypted-XML fallback could run.

I've pushed one small commit on top of yours rather than going back and forth on nits. It writes the check as valid === undefined, pins the expected error messages in the new tests, and adds a direct validateSignature test for a digest mismatch with multiple certificates. Your commit is untouched. Shout if you disagree with any of it, otherwise I'll get this merged once CI is green.

@deepakprabhakara
deepakprabhakara merged commit 6d79122 into ory:main Nov 22, 2026
6 checks passed
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.

3 participants