0Pricing
Cyber Security Academy · Lesson

SAML and Federation

Enterprise single sign-on.

SAML and Federation is a free Cyber Security Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cyber Security Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What SAML Is

SAML (Security Assertion Markup Language) is an XML-based standard for exchanging authentication and authorization data, dominant in enterprise SSO.

  • It lets a corporate identity provider vouch for a user to many applications.
  • SAML 2.0 predates OIDC and remains entrenched in B2B and workforce identity.

Understanding SAML is essential for defending enterprise federation, where a single trust flaw exposes every connected app.

IdP and SP Roles

SAML federation has two principal parties.

  • Identity Provider (IdP) authenticates the user and issues assertions (Okta, Entra ID, Ping).
  • Service Provider (SP) the application that trusts the IdP and grants access.

Trust is established out of band by exchanging metadata, including signing certificates and endpoint URLs.

IdP  -> authenticates user, signs assertion
SP   -> consumes assertion, grants access
Metadata exchange establishes trust (certs, ACS URLs)

The SAML Assertion

The core artifact is the assertion, an XML document stating that the IdP authenticated a subject.

  • Subject identifies the user (NameID).
  • Conditions define validity window and intended audience.
  • AuthnStatement records how/when authentication occurred.
  • AttributeStatement carries roles, email, group claims.
<saml:Assertion>
  <saml:Subject><saml:NameID>user@corp</saml:NameID></saml:Subject>
  <saml:Conditions NotOnOrAfter="2026-06-04T10:05:00Z"
     AudienceRestriction="https://sp.example"/>
  <saml:AuthnStatement .../>
</saml:Assertion>

SP-Initiated SSO Flow

The most common pattern is SP-initiated SSO.

  • User hits the SP, which generates an AuthnRequest and redirects to the IdP.
  • The IdP authenticates the user and POSTs a signed Response back to the SP Assertion Consumer Service (ACS).
  • The SP validates the assertion and creates a local session.
1. SP -> AuthnRequest -> IdP (redirect)
2. user authenticates at IdP
3. IdP -> signed SAMLResponse -> SP ACS (HTTP POST)
4. SP validates -> session

XML Signatures Anchor Trust

SAML security rests on XML digital signatures. The IdP signs the assertion (and/or the response) with its private key; the SP verifies with the trusted certificate.

  • Sign the assertion itself, not merely the outer response.
  • Verify the signature against a pinned IdP certificate from metadata, not one embedded in the message.

Most SAML attacks target the signature validation logic.

XML Signature Wrapping (XSW)

XML Signature Wrapping is the signature attack class for SAML. The attacker keeps a validly signed element but adds a second, forged assertion that the application logic actually reads.

  • The signature still verifies against the original fragment.
  • But the business logic processes the injected, unsigned assertion.

Mitigation: use a hardened SAML library, validate that the signed element is the one consumed, and reject documents with multiple/ambiguous assertions.

Document after XSW:
  <Response>
    <Assertion id="evil">attacker claims</Assertion>  // read by app
    <Assertion id="orig" SIGNED>real user</Assertion>  // sig valid here
  </Response>

Audience and Recipient Restrictions

An assertion must be bound to the intended SP. SAML provides explicit restrictions.

  • AudienceRestriction names the SP entity ID the assertion is valid for.
  • Recipient in SubjectConfirmation must match the ACS URL.

The SP must enforce these. Skipping the audience check lets an assertion minted for one app be replayed to another.

Replay and Timing Defenses

Assertions are short-lived, single-use credentials. SPs must enforce that.

  • Honor NotBefore and NotOnOrAfter with tight clock skew.
  • Track the assertion ID and reject any reuse within the validity window.
  • Require TLS on the ACS endpoint.

Without replay tracking, a captured assertion can be submitted again before it expires.

SP checks:
  now in [NotBefore, NotOnOrAfter]  (+- small skew)
  assertion.ID not seen before -> store + reject reuse

Federation and Trust Chains

Federation scales SSO across organizational boundaries, sometimes via hubs or brokers that translate between protocols.

  • Each trust link is a potential weak point; a compromised IdP impersonates every user.
  • Identity brokers may bridge SAML and OIDC, requiring careful claim mapping.

Apply least privilege to attribute mapping and monitor for unexpected new SP registrations.

Common SAML Weaknesses

Recurring SAML failure modes worth auditing:

  • Signature not verified, or response signed but assertion not.
  • Vulnerable to XML Signature Wrapping.
  • Missing audience/recipient checks.
  • No replay protection or overly long validity windows.
  • XML External Entity (XXE) parsing on the SP.
  • Trusting the certificate embedded in the message instead of pinned metadata.
Disable external entities in the XML parser:
  parser.setFeature(
    "http://apache.org/xml/features/disallow-doctype-decl", true)

SAML vs OIDC

Both deliver SSO, but differ in design.

  • SAML XML, browser POST/redirect bindings, heavy in enterprise/workforce, mature tooling.
  • OIDC JSON/JWT, REST-friendly, better for mobile and SPAs.

Many organizations run both. Defenders should know the assertion-validation rules for whichever protocol a given app uses, since the attack surface differs.

Quick Check: Defeating XSW

Select the best defense for the described attack.

Recap: SAML and Federation

Key takeaways:

  • SAML is XML-based enterprise SSO between an IdP and SP using signed assertions.
  • Security depends on correct XML signature validation against a pinned certificate.
  • Defend against XML Signature Wrapping, replay, and XXE.
  • Always enforce audience/recipient restrictions and validity windows.
  • Federation scales trust but multiplies the blast radius of a compromised IdP.

Frequently asked questions

Is the “SAML and Federation” lesson free?

Yes — the full text of “SAML and Federation” is free to read here on the web, and the Cyber Security Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cyber Security Academy course, upgrade to CoddyKit PRO.

What will I learn in “SAML and Federation”?

Enterprise single sign-on. You practise Cyber Security Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Cyber Security Academy?

No prior experience is required. Cyber Security Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “SAML and Federation” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Cyber Security Academy lesson?

Yes. Every Cyber Security Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. OAuth 2.0 Flows
  2. OpenID Connect (OIDC)
  3. SAML and Federation
  4. Token Attacks and Hardening
← Back to Cyber Security Academy