Springboot security

From xu-xiang/everything-claude-code-zh · View interactive version

Springboot security is an AI agent skill from the GitHub repository xu-xiang/everything-claude-code-zh. Spring Boot 服务的 Spring Security 身份验证/授权、验证、CSRF、密钥、响应头、速率限制和依赖项安全最佳实践。

How to use this skill

Skill file

Spring Boot 安全审查

在添加身份验证、处理输入、创建端点或处理敏感密钥时使用。

身份验证(Authentication)

@Component
public class JwtAuthFilter extends OncePerRequestFilter {
  private final JwtService jwtService;

  public JwtAuthFilter(JwtService jwtService) {
    this.jwtService = jwtService;
  }

  @Override
  protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
      FilterChain chain) throws ServletException, IOException {
    String header = request.getHeader(HttpHeaders.AUTHORIZATION);
    if (header != null && header.startsWith("Bearer ")) {
      String token = header.substring(7);
      Authentication auth = jwtService.authenticate(token);
      SecurityContextHolder.getContext().setAuthentication(auth);
    }
    chain.doFilter(request, response);
  }
}

授权(Authorization)

输入验证(Input Validation)

SQL 注入防护

CSRF 防护

http
  .csrf(csrf -> csrf.disable())
  .sessionManagement(sm -> sm.sessionCreationPolicy(SessionCreationPolicy.STATELESS));

密钥管理(Secrets Management)

安全响应头(Security Headers)

http
  .headers(headers -> headers
    .contentSecurityPolicy(csp -> csp
      .policyDirectives("default-src 'self'"))
    .frameOptions(HeadersConfigurer.FrameOptionsConfig::sameOrigin)
    .xssProtection(Customizer.withDefaults())
    .referrerPolicy(rp -> rp.policy(ReferrerPolicyHeaderWriter.ReferrerPolicy.NO_REFERRER)));

速率限制(Rate Limiting)

依赖项安全(Dependency Security)

日志与 PII(个人识别信息)

文件上传

发布前检查清单

注意:默认拒绝(Default Deny)、验证输入、应用最小权限原则,并优先采用“配置即安全”的实践。

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.