Skip to main content

Overview

SuperTokens Core implements multiple layers of security including industry-standard password hashing, JWT signing with key rotation, token encryption, and protection against common attacks.

Password Security

Password Hashing Algorithms

SuperTokens supports multiple password hashing algorithms:

Argon2

Memory-hard algorithm, best security (default)

BCrypt

Industry standard, configurable work factor

Firebase SCrypt

For Firebase migrations

Argon2 Configuration

From io/supertokens/emailpassword/PasswordHashing.java:
number
default:"1"
Number of iterations (time cost)
number
default:"87795"
Memory usage in KB (~85 MB)
number
default:"2"
Number of parallel threads
number
default:"1"
Thread pool size for hashing operations

BCrypt Configuration

number
default:"11"
Work factor (2^11 = 2048 rounds)
Higher log rounds increase security but slow down authentication. 11 rounds takes approximately 100-200ms.

Firebase SCrypt

For migrating from Firebase:
string
Base64-encoded signer key from Firebase
string
Base64-encoded salt separator
number
default:"8"
Number of rounds used in Firebase
number
default:"14"
Memory cost parameter

Token Signing

JWT Signing Keys

SuperTokens uses RS256 (RSA with SHA-256) for signing JWTs:

Key Types

Dynamic Keys

Rotate automatically, used for access tokens by default

Static Keys

Never rotate, used for custom JWTs and special cases

Key Rotation

From io/supertokens/signingkeys/SigningKeys.java:
1

Generate New Key

Create new RSA key pair every access_token_signing_key_update_interval hours
2

Transition Period

Old keys remain valid for token verification during their lifetime
3

Clean Up

Remove expired keys from storage
number
default:"168"
Hours between key rotations (default: 7 days)
number
default:"168"
Hours between dynamic key rotations

JWT Creation

From io/supertokens/jwt/JWTSigningFunctions.java:84-147:

JWKS Endpoint

Public keys are exposed via JWKS endpoint:

Token Encryption

Refresh Token Encryption

Refresh tokens are encrypted using AES-256-CBC:

Encryption Key Storage

Refresh token encryption keys are stored securely in the database and cached in memory.
Never log or expose refresh tokens. They contain encrypted user session data.

Attack Prevention

Token Theft Detection

SuperTokens detects token theft through refresh token rotation: From io/supertokens/session/Session.java:652-654:

Anti-CSRF Protection

boolean
default:"true"
Enable anti-CSRF token validation
Anti-CSRF tokens:
  • Generated as random UUIDs
  • Stored in both access and refresh tokens
  • Validated on session verification and refresh
  • Sent as separate header or cookie

Session Blacklisting

Optional database verification to detect revoked sessions:
Database checks add latency but provide immediate session invalidation. Without them, revoked sessions remain valid until access token expiry.

Rate Limiting

number
default:"10"
Maximum concurrent requests per core instance
Built-in connection pooling prevents resource exhaustion.

Secure Storage

Password Reset Tokens

Password reset tokens are:
  • Randomly generated UUIDs
  • Hashed before storage using SHA-256
  • Single-use only
  • Time-limited (configurable expiry)
number
default:"3600000"
Reset token lifetime in milliseconds (default: 1 hour)

Email Verification Tokens

Similar to password reset tokens:
  • UUID-based
  • Hashed in database
  • Single-use
  • Time-limited
number
default:"86400000"
Verification token lifetime in milliseconds (default: 24 hours)

Cryptographic Operations

Hashing Utilities

From io/supertokens/utils/Utils.java:

AES Encryption/Decryption

Database Security

SQL Injection Prevention

All database queries use parameterized statements:

Connection Pooling

number
default:"10"
PostgreSQL connection pool size
number
default:"10"
MySQL connection pool size
Connection pooling prevents:
  • Connection exhaustion attacks
  • Resource leaks
  • Performance degradation

Configuration Security

Protected Configurations

From io/supertokens/multitenancy/Multitenancy.java:174-179: These configs cannot be changed after tenant creation:
  • Database connection parameters
  • Core service ports
  • Base paths
  • API keys
  • Signing keys

API Key Security

string
Comma-separated list of API keys for core authentication
API keys must be:
  • At least 20 characters
  • Randomly generated
  • Stored securely (environment variables, secrets manager)
  • Rotated periodically
Never commit API keys to version control. Use environment variables or secret management systems.

Security Headers

SuperTokens sets secure HTTP headers:

CORS Configuration

string
Comma-separated list of allowed domains for CORS

Audit Logging

Enable detailed logging for security audits:
string
default:"INFO"
Logging level: DEBUG, INFO, WARN, ERROR
string
Path to info log file
string
Path to error log file

Best Practices

Use Argon2

Default password hashing algorithm provides best security

Enable Key Rotation

Use dynamic keys with regular rotation intervals

Enable Anti-CSRF

Always enable for web applications

Monitor for Theft

Log TokenTheftDetectedException events

Use HTTPS Only

Never transmit tokens over unencrypted connections

Rotate API Keys

Periodically update API keys and remove old ones

Security Checklist

1

Configure Password Hashing

Set appropriate Argon2 or BCrypt parameters for your use case
2

Set Token Lifetimes

Balance security and user experience with token validity periods
3

Enable HTTPS

Ensure all communication uses TLS 1.2 or higher
4

Configure CORS

Whitelist only trusted domains
5

Set API Keys

Use strong, random API keys and rotate them regularly
6

Enable Logging

Configure audit logging for security events
7

Review Permissions

Follow principle of least privilege for tenant operations