wasAsked.

How would you review a pull request that changes Spring Security authentication and authorization?

BrowserStack · Full Stack Developer · 3-4-years · technical

Published

Year not specified · Java, Spring Security, Authentication & Security

Community answers

Posted by wasAsked editorial collection

Authentication and authorization changes need a careful, checklist-driven review. Understand intent and scope - What problem does the change solve? Which endpoints, roles and clients are affected? Ask for tests showing both allowed and denied scenarios. SecurityFilterChain configuration - Rule order: Spring Security evaluates requestMatchers in order, so a broad permitAll() placed before specific rules can expose endpoints. Ensure the last rule is anyRequest().authenticated() (or denyAll()). - Check for new permitAll() entries, including wildcard patterns that match more than intended (/api/** vs /api/public/**). - Multiple filter chains: check securityMatcher and @Order so the right chain handles each request. - Matchers should be specific (HTTP method plus path); Spring Security 6 uses PathPatternRequestMatcher-style matching, so check that patterns behave as expected. Authentication - JWT validation: issuer-uri or jwk-set-uri correct, audience validation present, no custom decoder that skips signature checks, expected algorithms only. - Session and cookie settings: Secure, HttpOnly, SameSite, session fixation protection, logout invalidating sessions. - CSRF: disabled only for stateless token-based APIs, never for cookie-authenticated endpoints. - Password storage uses a DelegatingPasswordEncoder or BCrypt/Argon2, never plain or weak hashing. - No hard-coded credentials, test users or secrets in configuration. Authorization - Method security enabled (@EnableMethodSecurity) where @PreAuthorize annotations are used; annotations on private methods or self-invoked methods do not apply through proxies. - Role vs authority naming: hasRole("ADMIN") expects ROLE_ADMIN; check JwtAuthenticationConverter mappings match what the identity provider issues. - Resource-level checks: users can access only their own or their tenant's records (IDOR protection), including list, export, download, bulk and WebSocket endpoints. Error handling and leakage - 401 vs 403 behaviour correct; error responses do not reveal stack traces or whether resources exist. - Logs do not contain tokens, passwords or full personal data. CORS and headers - Allowed origins specific; credentials not combined with wildcard origins; security headers (CSP, HSTS, frame options) intact. Tests and evidence - spring-security-test cases for anonymous, wrong role, wrong tenant, expired or tampered tokens, and allowed users. - Dependency changes (Spring Security version upgrades) reviewed against migration guides. For high-risk changes, request a second reviewer with security expertise and consider a quick threat model.

Ravindra Wadile · · 0 likes

Sign in to add your answer

Related interview topics