Add AssertionExtension for extensible SAML assertions#245
Open
pelted wants to merge 2 commits intosaml-idp:masterfrom
Open
Add AssertionExtension for extensible SAML assertions#245pelted wants to merge 2 commits intosaml-idp:masterfrom
pelted wants to merge 2 commits intosaml-idp:masterfrom
Conversation
- Introduced `assertion_extension` attribute in `AssertionBuilder`, `SamlResponse`, and `Controller`. - Updated initialization methods to accept `assertion_extension` as an option. - Enhanced the `build` methods to utilize `assertion_extension` for customizing subject confirmation data and authentication context. - Ensured backward compatibility by maintaining existing functionality when no extension is provided.
- Enhanced comments in the AssertionExtension class to clarify its purpose and usage. - Provided details on the expected implementation of subclasses and alignment with SAML 2.0 specifications. - Added references to external documentation for further specification analysis.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds an AssertionExtension hook so consumers of
saml_idpcan extend the SAML assertion XML at two specification-defined extension points: SubjectConfirmationData and AuthnContextDecl. When no extension is provided, behavior is unchanged and the assertion is built exactly as today.Motivation
Some IdP deployments need to include custom XML in the assertion—for example, device trust or zero-trust context inside
<AuthnContextDecl>, or extra confirmation data inside<SubjectConfirmationData>. The SAML 2.0 Core spec explicitly allows arbitrary elements/attributes at these points (Sections 2.4.1.2 and 2.7.2.2), but the gem currently has no way to inject them without forking. This feature provides a small, optional API to do that.Extension points
AssertionExtension::SUBJECT_CONFIRMATION_DATA_EXTENSION_POINT<SubjectConfirmation><SubjectConfirmationData>(with standard attributes when using bearer) and any extra elements/attributes.AssertionExtension::AUTHN_CONTEXT_DECL_EXTENSION_POINT<AuthnContext>, after<AuthnContextClassRef><AuthnContextDecl>,<AuthnContextDeclRef>, or other AuthnContext children.Usage
1. Define a subclass that implements
#build(context). Thecontextis a Builder block for either the SubjectConfirmation element (SubjectConfirmationData extension) or the AuthnContext element (AuthnContextDecl extension).2. Pass the extension when encoding the authn response (e.g. in your IdP controller):
If
assertion_extensionis omitted ornil, the assertion is built with the current default behavior (no custom XML).API surface
lib/saml_idp/assertion_extension.rb— base class withextension_pointand abstract#build(context).encode_authn_response(principal, opts)accepts optionalopts[:assertion_extension].assertion_extensionis threaded through and used only when present and when the extension’sextension_pointmatches the current build step.All new parameters are optional and default to
nil; existing callers are unaffected.Backward compatibility
assertion_extensionis not passed, the generated assertion XML is identical to the current implementation.SAML 2.0 alignment
The two extension points correspond to:
<SubjectConfirmationData>.<AuthnContextDecl>(and related elements) inside<AuthnContext>alongside<AuthnContextClassRef>.We always emit
<AuthnContextClassRef>first; the extension then adds declaration content. For SubjectConfirmationData, the extension is responsible for emitting<SubjectConfirmationData>(including standard attributes likeNotOnOrAfter,Recipient,InResponseTofor bearer) and any custom content, so that standard SPs still validate the assertion.Testing
spec/lib/saml_idp/assertion_extension_spec.rb— base class behavior, extension point constants, and a subclass that implements#build.assertion_builder_spec,saml_response_spec, andcontroller_specremain valid; the default (no extension) path is unchanged.Checklist
AssertionExtension; existing specs still pass with no extension.