Loading...
Loading...
OWASP security guidelines and Top 10 vulnerabilities USE WHEN: user mentions "OWASP", "security audit", "vulnerability scan", asks about "injection", "XSS", "CSRF", "access control", "authentication security" DO NOT USE FOR: OWASP Top 10:2025 specific - use `owasp-top-10` instead
npx skill4agent add claude-dev-suite/claude-dev-suite owaspowasp-top-10secrets-managementsupply-chainDeep Knowledge: Usewith technology:mcp__documentation__fetch_docsfor comprehensive documentation.owasp
// BAD - Direct object reference
@GetMapping("/users/{id}")
public User getUser(@PathVariable Long id) {
return userRepository.findById(id);
}
// GOOD - Check authorization
@GetMapping("/users/{id}")
public User getUser(@PathVariable Long id, Authentication auth) {
User user = userRepository.findById(id);
if (!user.getId().equals(auth.getPrincipal().getId())) {
throw new AccessDeniedException("Not authorized");
}
return user;
}// BAD - Weak hashing
String hash = DigestUtils.md5Hex(password);
// GOOD - Strong hashing with salt
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
String hash = encoder.encode(password);// BAD - SQL Injection
String query = "SELECT * FROM users WHERE name = '" + name + "'";
// GOOD - Parameterized query
@Query("SELECT u FROM User u WHERE u.name = :name")
User findByName(@Param("name") String name);# Spring Security - disable defaults carefully
spring:
security:
headers:
content-security-policy: "default-src 'self'"
x-frame-options: DENY
x-content-type-options: nosniff# Check for vulnerabilities
npm audit
mvn dependency-check:check
pip-audit// Implement rate limiting
@RateLimiter(name = "login", fallbackMethod = "loginFallback")
public AuthResponse login(LoginRequest request) {
// ...
}
// Account lockout
if (failedAttempts >= 5) {
lockAccount(user);
}// Log security events
log.info("Login attempt", Map.of(
"user", username,
"ip", request.getRemoteAddr(),
"success", authenticated
));
// DON'T log sensitive data
log.info("Password: {}", password); // NEVER!// Validate URLs
private boolean isAllowedUrl(String url) {
URL parsed = new URL(url);
return allowedHosts.contains(parsed.getHost());
}@Configuration
public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) {
return http
.headers(headers -> headers
.contentSecurityPolicy(csp -> csp.policyDirectives("default-src 'self'"))
.frameOptions(frame -> frame.deny())
.xssProtection(xss -> xss.disable())
)
.build();
}
}| Anti-Pattern | Why It's Bad | Correct Approach |
|---|---|---|
| Direct object references without auth | IDOR vulnerability (A01) | Always verify ownership before access |
| Using MD5/SHA1 for passwords | Easily cracked | Use bcrypt/argon2 with salt |
| String concatenation in SQL | SQL injection | Use parameterized queries/ORMs |
| Exposing stack traces in prod | Information disclosure | Generic error messages only |
| No rate limiting on login | Brute force attacks | Implement rate limiting + account lockout |
| Storing secrets in code | Credential exposure | Use environment variables/vaults |
| Issue | Likely Cause | Solution |
|---|---|---|
| 403 Forbidden on valid request | CORS misconfiguration | Check allowed origins in CORS config |
| Session not persisting | SameSite cookie issue | Set |
| JWT token rejected | Clock skew or expired | Add clock skew tolerance (5min) |
| File upload fails | CSP blocking | Add upload domain to CSP directives |
| API returns 401 unexpectedly | Missing/invalid Authorization header | Check Bearer token format |