Skip to content

Instantly share code, notes, and snippets.

@aravindkumarsvg
Last active July 24, 2025 09:34
Show Gist options
  • Select an option

  • Save aravindkumarsvg/ceeb82c28765d510f1509c5aac216bfa to your computer and use it in GitHub Desktop.

Select an option

Save aravindkumarsvg/ceeb82c28765d510f1509c5aac216bfa to your computer and use it in GitHub Desktop.
SAML SSO - VAPT

πŸ›‘οΈ SAML SSO - Flow, Parameters, and VAPT Checklist

SAML is primarily used for single sign-on (SSO) and authentication within enterprise environments

πŸ”„ SAML SSO Flow – SP-Initiated (Typical)

1. User Requests Resource (SP)

  • User tries to access a protected page.
  • SP generates a SAMLRequest and redirects to IdP.

2. SAML AuthnRequest (SP β†’ IdP)

  • HTTP Method: GET (Redirect Binding)
  • Parameters:
    • SAMLRequest: Base64+DEFLATE encoded XML AuthnRequest
    • RelayState: Optional state (e.g. return URL)
  • Inside AuthnRequest XML:
    • Issuer: SP Entity ID
    • ID: Unique identifier
    • IssueInstant: Timestamp
    • Destination: IdP SSO URL
    • AssertionConsumerServiceURL: Where IdP should send response
    • NameIDPolicy: Format of user identity
    • ForceAuthn: Force reauthentication

3. User Authenticates with IdP

  • Google Workspace prompts login or uses existing session.

4. SAML Response (IdP β†’ SP)

  • HTTP Method: POST (Browser auto-submits form)
  • Form Fields:
    • SAMLResponse: Base64-encoded, signed XML response
    • RelayState: (if present in request)
  • Inside SAML Response:
    • <saml:Assertion>:
      • Issuer: IdP Entity ID
      • Subject: Includes NameID
      • Conditions:
        • NotBefore, NotOnOrAfter
        • AudienceRestriction β†’ SP Entity ID
      • AttributeStatement: Contains user attributes like email, groups
      • Signature: Ensures authenticity

5. SP Validates Response and Establishes Session

  • Checks signature, timestamps, audience, and user attributes.

πŸ“¦ Important SAML Parameters

Parameter Location Purpose
SAMLRequest Redirect URL Encoded AuthnRequest from SP
RelayState Redirect URL & POST SP-specific state value
SAMLResponse POST Form Encoded signed XML Assertion from IdP
NameID Inside <Subject> User identity (email, etc.)
Audience Inside <Conditions> Valid SP audience (must match SP)
NotBefore, NotOnOrAfter Inside <Conditions> Validity time window
AttributeStatement Inside <Assertion> Custom user data (e.g. groups, roles)

βœ… SAML VAPT Checklist

πŸ” Signature & Assertion Validation

  • Is the SAMLResponse signature verified?
  • Does SP enforce Audience matching?
  • Are NotBefore and NotOnOrAfter validated correctly?
  • Is the Issuer checked against trusted IdPs?

🎯 RelayState and Redirect Attacks

  • Can RelayState be used for open redirect?
  • Does SP validate trusted redirect URLs?

🧬 Assertion Tampering

  • Can you alter groups or email in Assertion and replay?
  • Does SP verify the signature of the assertion itself?

πŸ›‘οΈ Replay & Expired Assertion Use

  • Can a valid SAMLResponse be reused?
  • Is a unique InResponseTo ID validated?

⚠️ Metadata / IdP Misconfig

  • Can you register or inject a malicious IdP?
  • Does the SP consume only known, static IdP metadata?

πŸ§ͺ Binding Confusion

  • Does SP support both POST and Redirect bindings?
  • Can you abuse inconsistent handling between bindings?

πŸ“š Tools for Testing

  • Burp Suite + SAML plugins (e.g., SAML Raider)
  • samltool.io / SAMLTracer browser extension
  • xmlsec1 – CLI for validating XML signatures
  • jwt.io – Though not for SAML, for JWT-based OIDC checks

βœ… Best Practices for SP Developers

  • Always verify signatures and audience
  • Use strict time validation (NotBefore, NotOnOrAfter)
  • Never trust user attributes unless assertion is verified
  • Use signed assertions and responses (WantAssertionsSigned=true)
  • Log and alert on replayed or malformed assertions
@aravindkumarsvg

Copy link
Copy Markdown
Author
SAML Flow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment