CHAPTER 4

Security & Authentication

Essential security practices, authentication mechanisms, encryption standards, and compliance requirements for protecting financial data in transit and at rest.

The Security Imperative

Financial data is among the most sensitive information exchanged electronically. A single breach can result in significant financial losses, regulatory penalties, and irreparable damage to reputation. Security must be designed into every layer of financial data exchange.

OAuth 2.0 & OpenID Connect

OAuth 2.0 is the industry standard for authorization, widely used in open banking and fintech APIs. OpenID Connect adds an identity layer on top of OAuth 2.0 for authentication.

OAuth 2.0 Flow for Open Banking

// Step 1: Client redirects user to authorization endpoint GET https://bank.example.com/oauth/authorize? response_type=code& client_id=CLIENT_ID& redirect_uri=https://app.example.com/callback& scope=accounts transactions& state=RANDOM_STATE // Step 2: User authenticates and grants consent // Step 3: Bank redirects back with authorization code https://app.example.com/callback?code=AUTH_CODE&state=RANDOM_STATE // Step 4: Client exchanges code for access token POST https://bank.example.com/oauth/token Content-Type: application/x-www-form-urlencoded grant_type=authorization_code& code=AUTH_CODE& redirect_uri=https://app.example.com/callback& client_id=CLIENT_ID& client_secret=CLIENT_SECRET // Step 5: Response with access token { "access_token": "eyJhbGciOiJSUzI1NiIs...", "token_type": "Bearer", "expires_in": 3600, "refresh_token": "tGzv3JOkF0XG5Qx2TlKWIA", "scope": "accounts transactions" }

Security Best Practices

JWT (JSON Web Tokens)

JWTs are self-contained tokens that carry claims about the user and can be verified without database lookups. They're commonly used in financial APIs for stateless authentication.

// JWT Structure: header.payload.signature // Header { "alg": "RS256", "typ": "JWT", "kid": "key-2025-01" } // Payload { "iss": "https://auth.bank.example.com", "sub": "user@example.com", "aud": "api.bank.example.com", "exp": 1735138200, "iat": 1735134600, "scope": "accounts:read transactions:read", "account_id": "ACC-12345" } // Signature (RS256) RSASHA256( base64UrlEncode(header) + "." + base64UrlEncode(payload), privateKey )

JWT Security Considerations

⚠️ Warning: Never put sensitive data like passwords or credit card numbers in JWT payloads. JWTs are encoded, not encrypted, and can be decoded by anyone.

Mutual TLS (mTLS)

Mutual TLS provides strong authentication by requiring both client and server to present certificates. It's commonly used for high-security B2B integrations and regulatory reporting.

mTLS Handshake Process

  1. Client initiates TLS connection to server
  2. Server presents its certificate to client
  3. Client validates server certificate against trusted CA
  4. Server requests client certificate
  5. Client presents its certificate to server
  6. Server validates client certificate
  7. Encrypted communication channel established

Certificate Management

Encryption Standards

Transport Layer Security (TLS 1.3)

TLS 1.3 is mandatory for all financial data exchange. It provides encryption, integrity, and authentication for data in transit.

Feature TLS 1.2 TLS 1.3
Handshake 2 round trips 1 round trip (faster)
Cipher Suites 37 options (many weak) 5 strong options only
Forward Secrecy Optional Always enabled
0-RTT Resumption No Yes (with replay protection)

Data at Rest Encryption

Financial data must be encrypted when stored in databases, file systems, or backups:

Tokenization

Tokenization replaces sensitive data with non-sensitive tokens, critical for PCI DSS compliance in payment systems.

// Original PAN (Primary Account Number) 4111 1111 1111 1111 // Tokenized (format-preserving) 4622 7890 1234 5678 // Token properties: // - Same length and format as original // - No mathematical relationship to original // - Useless to attackers without tokenization system // - Can be used for display and routing

Tokenization vs Encryption

Aspect Tokenization Encryption
Reversibility Lookup in vault required Decrypt with key
Format Can preserve format Different format
PCI DSS Scope Reduces scope significantly Still in scope
Performance Lookup overhead CPU overhead

Compliance Requirements

PCI DSS (Payment Card Industry Data Security Standard)

Any organization that stores, processes, or transmits credit card data must comply with PCI DSS:

GDPR (General Data Protection Regulation)

When processing EU citizens' data, implement these GDPR requirements:

PSD2 (Payment Services Directive 2)

European regulation requiring Strong Customer Authentication (SCA) and secure communication:

Security Best Practices

Defense in Depth

Implement multiple layers of security controls:

  1. Network Layer: Firewalls, IDS/IPS, DDoS protection
  2. Application Layer: WAF, API gateway, rate limiting
  3. Data Layer: Encryption, tokenization, access controls
  4. Identity Layer: MFA, RBAC, principle of least privilege
  5. Monitoring Layer: SIEM, anomaly detection, audit logs

API Security

// Security headers for financial APIs Strict-Transport-Security: max-age=31536000; includeSubDomains X-Content-Type-Options: nosniff X-Frame-Options: DENY X-XSS-Protection: 1; mode=block Content-Security-Policy: default-src 'self' Referrer-Policy: no-referrer Permissions-Policy: geolocation=(), microphone=(), camera=() // Rate limiting X-RateLimit-Limit: 100 X-RateLimit-Remaining: 87 X-RateLimit-Reset: 1735138200 // API versioning API-Version: 2.0

Incident Response

Prepare for security incidents with a comprehensive response plan:

Security is not a one-time implementation but an ongoing process. Regular audits, penetration testing, and security training are essential for maintaining robust protection of financial data.