Java Authentication and Configuration Security Source Code Audit
- 攻击大类:C09 Web应用漏洞利用
Authentication, authorization, and security configuration are the highest-yield vulnerability surfaces in Java backend projects. This skill provides complete detection approaches for 6 major categories of white-box audit, applicable to Spring Boot/Spring Security, Apache Shiro, and custom frameworks.
Related Skills
java-framework-audit— Spring/Struts/MyBatis framework auditsjava-injection-audit— SQL/OGNL/EL injection auditsjava-serialization-audit— deserialization vulnerability auditsidor-methodology— black-box IDOR testing methodology
Further Reading
- Detailed patterns for the 6 vulnerability categories (dangerous code/safe code/EVID evidence) -> references/auth-config-patterns.md
Quick Reference Table of the 6 Risk Categories
| # | Category | Key search entry points | Severity |
|---|---|---|---|
| 1 | Authentication bypass | SecurityConfig, ShiroFilterFactory, doFilter |
Critical |
| 2 | Broken access control | DAO/Mapper query statements, @PreAuthorize, Controller parameters |
High |
| 3 | JWT security | Jwts.parser(), Algorithm.HMAC, SECRET_KEY |
High |
| 4 | Crypto configuration | MessageDigest, Cipher.getInstance, new Random() |
High |
| 5 | Information disclosure | application.yml Actuator configuration, @ExceptionHandler |
Medium |
| 6 | Business logic | balance/stock operations, state machine transitions, payment callbacks | High |
1. Authentication Bypass Audit Points
- Spring Security: check
FilterChainProxymatching rules, the differences betweenAntPathRequestMatcherandMvcRequestMatcher(trailing slash/path suffix);requestMatchersordering—a permissivepermitAll()rule placed first overrides later interceptors; whetherpermitAll()is overly broad (e.g./api/**) - Shiro: bypass caused by URI parsing differences—
/admin/vs/adminvs/admin/..;/; path normalization bypass series such as CVE-2020-1957 / CVE-2020-11989 / CVE-2020-13933 - Custom Filter: an early return in
doFilter()causes the rest of the chain not to execute; sloppy allowlist regex (e.g.startsWith("/public")also matches/publicevil)
2. Broken Access Control Audit Points
- Horizontal privilege escalation: the endpoint only validates login state but not resource ownership—the DAO layer
WHERE id = #{orderId}lacks theAND user_id = #{currentUserId}condition - Vertical privilege escalation: Controller/Service methods lack role annotations
@PreAuthorize/@RequiresRoles; enum values (role IDs) are guessable - IDOR: auto-increment IDs can be enumerated; whether UUIDs are truly unpredictable; bulk endpoints skip per-item permission checks
3. JWT Security Audit Points
- Algorithm confusion:
alg: nonebypasses signature verification; RS256 -> HS256 attack (using the public key as the HMAC key) - Hardcoded keys:
SECRET_KEY = "xxx"in source code or plaintext configuration inapplication.yml - Missing Claims validation:
exp(expiry)/iss(issuer)/aud(audience) are unvalidated, allowing tokens to be reused across environments - Refresh mechanism:
refresh_tokenis long-lived and not bound to a user/device, allowing unlimited refresh after theft
4. Crypto Configuration Audit Points
- Weak algorithms:
MD5/SHA1for password hashing,DES/RC4for encryption,ECBmode (leaks data patterns) - Correct practice: use
bcrypt/scrypt/argon2for passwords; useAES-GCM/AES-CBC+HMACfor symmetric encryption - Hardcoded keys/salts:
private static final String KEY = "..."or the salt hardcoded in code - Insecure randomness:
java.util.Randomis predictable; security-sensitive scenarios must useSecureRandom
5. Information Disclosure Audit Points
- Exposed Actuator endpoints:
/env(environment variables/passwords),/heapdump(heap memory containing keys),/jolokia(remote code execution) - Verbose error stack traces: no global exception handler, SQL errors/class names/paths returned directly to the client
- Debug mode:
server.error.include-stacktrace=always,spring.devtoolsnot removed - Sensitive data in logs:
log.info("user password: {}", password)or full credit card numbers written to log files
6. Business Logic Audit Points
- Concurrency race: balance check and deduction are non-atomic (double-spending); coupon/points replay
- Parameter tampering: amount/quantity/discount are passed by the client and not recomputed server-side; order amounts can be negative
- Process bypass: multi-step flows (register-verify-set password) lack state validation between steps, allowing a direct jump to later endpoints
Detection Checklist
Confirm each item during the audit and record EVID evidence for every finding:
- Spring Security configuration chain ordering issues or overly broad
permitAll - Shiro
filterChainDefinitionMapURI parsing difference bypass - Custom Filter/Interceptor early return or allowlist bypass
- Whether data queries bind the current user ID (horizontal privilege escalation)
- Whether sensitive endpoints have role/permission annotations (vertical privilege escalation)
- Whether JWT enforces a specified algorithm + secure key storage + full Claims validation
- Password storage bcrypt/scrypt/argon2; symmetric encryption AES-GCM with no hardcoded keys
- Random number generation uses SecureRandom
- Actuator endpoints restricted + protected by authentication
- Global exception handler swallows stack traces; debug/devtools disabled in production; no sensitive data in logs
- Atomicity of amount/stock operations; state machine validation for multi-step flows