Blog | G5 Cyber Security

SSO Token Security: SAML & OpenID Connect

TL;DR

Single Sign-On (SSO) using SAML and OpenID Connect relies on tokens to prove a user’s identity. This guide explains how to keep those tokens secure, covering best practices for configuration, validation, and monitoring.

1. Understand Your Tokens

Before securing them, know what you’re dealing with:

Each token type has different security considerations.

2. Secure Configuration

  1. Metadata Exchange: Use HTTPS for exchanging SAML metadata (Identity Provider & Service Provider). This prevents man-in-the-middle attacks.
  2. Entity IDs: Ensure Entity IDs are unique and properly configured on both sides of the SSO connection. Incorrect configuration can lead to token misdirection.
  3. Binding Methods: Prefer secure binding methods like HTTP-POST or HTTPS Redirect for SAML. Avoid less secure options like HTTP GET.
  4. OpenID Connect Discovery: Use the OpenID Connect discovery endpoint (https://openid.net/specs/discovery/) to dynamically retrieve configuration details, reducing manual errors.

3. Token Validation

Rigorous validation is crucial. Here’s how:

  1. Digital Signature Verification: Always verify the digital signature of SAML Assertions and OpenID Connect ID Tokens using the trusted public key from the Identity Provider (IdP).
  2. # Example Python with PyJWT (OpenID Connect)
    import jwt
    
    public_key = "--Your Public Key--"
    token = "--Your ID Token--"
    
    decoded_token = jwt.decode(token, public_key, algorithms=['RS256'])
    print(decoded_token)
  3. Audience (aud) Claim: Verify the aud claim in OpenID Connect tokens matches your application’s Client ID. This ensures the token is intended for you.
  4. Issuer (iss) Claim: Validate the iss claim to confirm the token originated from a trusted IdP.
  5. Expiration Time (exp) Claim: Check that the token hasn’t expired. Reject tokens with an invalid expiration time.
  6. Subject (sub) Claim: Use the sub claim as the unique identifier for the user within your application.
  7. SAML Conditions: Carefully review SAML conditions (e.g., AudienceRestriction, NameIDPolicy) to ensure they align with your security requirements.

4. Token Handling Best Practices

5. Monitoring and Logging

  1. Log Token Validation Failures: Log any instances where token validation fails, including the reason for failure. This helps identify potential attacks or configuration issues.
  2. Monitor Authentication Events: Track successful and failed authentication attempts to detect suspicious activity.
  3. Regular Security Audits: Conduct regular security audits of your SSO implementation to identify vulnerabilities and ensure best practices are being followed.

6. Cyber security Considerations

Exit mobile version