springboot-security
Spring Boot 服务的 Spring Security 身份验证/授权、验证、CSRF、密钥、响应头、速率限制和依赖项安全最佳实践。
Best use case
springboot-security is best used when you need a repeatable AI agent workflow instead of a one-off prompt. It is especially useful for teams working in multi. Spring Boot 服务的 Spring Security 身份验证/授权、验证、CSRF、密钥、响应头、速率限制和依赖项安全最佳实践。
Spring Boot 服务的 Spring Security 身份验证/授权、验证、CSRF、密钥、响应头、速率限制和依赖项安全最佳实践。
Users should expect a more consistent workflow output, faster repeated execution, and less time spent rewriting prompts from scratch.
Practical example
Example input
Use the "springboot-security" skill to help with this workflow task. Context: Spring Boot 服务的 Spring Security 身份验证/授权、验证、CSRF、密钥、响应头、速率限制和依赖项安全最佳实践。
Example output
A structured workflow result with clearer steps, more consistent formatting, and an output that is easier to reuse in the next run.
When to use this skill
- Use this skill when you want a reusable workflow rather than writing the same prompt again and again.
When not to use this skill
- Do not use this when you only need a one-off answer and do not need a reusable workflow.
- Do not use it if you cannot install or maintain the related files, repository context, or supporting tools.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/springboot-security/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How springboot-security Compares
| Feature / Agent | springboot-security | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Spring Boot 服务的 Spring Security 身份验证/授权、验证、CSRF、密钥、响应头、速率限制和依赖项安全最佳实践。
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Spring Boot 安全审查
在添加身份验证、处理输入、创建端点或处理敏感密钥时使用。
## 身份验证(Authentication)
- 优先使用无状态 JWT 或带有吊销列表的不透明令牌(Opaque Token)
- 对于会话,使用 `httpOnly`、`Secure`、`SameSite=Strict` 的 Cookie
- 在 `OncePerRequestFilter` 或资源服务器中验证令牌
```java
@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)
- 启用方法级安全:`@EnableMethodSecurity`
- 使用 `@PreAuthorize("hasRole('ADMIN')")` 或 `@PreAuthorize("@authz.canEdit(#id)")`
- 默认拒绝访问,仅公开必要的范围(Scope)
## 输入验证(Input Validation)
- 在控制器中使用 `@Valid` 进行 Bean Validation
- 在 DTO 上应用约束:`@NotBlank`、`@Email`、`@Size` 以及自定义校验器
- 在渲染前使用白名单对 HTML 进行清理(Sanitize)
## SQL 注入防护
- 使用 Spring Data Repository 或参数化查询
- 原生查询使用 `:param` 绑定,禁止字符串拼接
## CSRF 防护
- 对于浏览器会话应用,启用 CSRF 并在表单/响应头中包含令牌
- 对于使用 Bearer 令牌的纯 API 应用,禁用 CSRF 并依赖无状态身份验证
```java
http
.csrf(csrf -> csrf.disable())
.sessionManagement(sm -> sm.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
```
## 密钥管理(Secrets Management)
- 禁止在源码中包含密钥。从环境变量或 Vault 加载
- 确保 `application.yml` 中不含凭据,使用占位符代替
- 定期轮换令牌和数据库凭证
## 安全响应头(Security Headers)
```java
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)
- 对高成本端点应用 Bucket4j 或网关级限制
- 记录突发流量日志并发送告警,返回带有重试提示的 429 状态码
## 依赖项安全(Dependency Security)
- 在 CI 中运行 OWASP Dependency Check / Snyk
- 保持 Spring Boot 和 Spring Security 处于受支持的版本
- 针对已知的 CVE 漏洞使构建失败
## 日志与 PII(个人识别信息)
- 禁止在日志中记录密钥、令牌、密码或完整的银行卡号(PAN)数据
- 脱敏敏感字段,并使用结构化 JSON 日志
## 文件上传
- 验证文件大小、内容类型(Content-Type)和扩展名
- 存储在 Web 根目录之外,并根据需要进行扫描
## 发布前检查清单
- [ ] 身份验证令牌已正确验证且未过期
- [ ] 所有敏感路径都有授权保护(Authorization Guard)
- [ ] 所有输入已验证并清理
- [ ] 没有通过字符串拼接的 SQL 语句
- [ ] 针对应用类型采用了正确的 CSRF 对策
- [ ] 密钥已外部化,未提交至仓库
- [ ] 已配置安全响应头
- [ ] API 设有速率限制
- [ ] 依赖项已扫描且为最新版本
- [ ] 日志中不含敏感数据
**注意**:默认拒绝(Default Deny)、验证输入、应用最小权限原则,并优先采用“配置即安全”的实践。Related Skills
springboot-verification
Spring Boot 项目的验证循环:构建、静态分析、带有覆盖率的测试、安全扫描以及发布或 PR 前的差异审查。
springboot-tdd
使用 JUnit 5, Mockito, MockMvc, Testcontainers 和 JaCoCo 进行 Spring Boot 的测试驱动开发(TDD)。适用于添加新功能、修复 bug 或重构场景。
springboot-patterns
Spring Boot 架构模式、REST API 设计、分层服务、数据访问、缓存、异步处理与日志。适用于 Java Spring Boot 后端开发。
security-scan
使用 AgentShield 扫描 Claude Code 配置(.claude/ 目录)中的安全漏洞、配置错误和注入风险。检查 CLAUDE.md、settings.json、MCP 服务端、钩子(Hooks)和智能体(Agents)定义。
django-security
Django 安全最佳实践、身份验证(Authentication)、授权(Authorization)、CSRF 防护、SQL 注入防御、XSS 防御以及安全部署配置。
security-review
当涉及添加身份验证(Authentication)、处理用户输入、操作机密(Secrets)、创建 API 终端节点或实现支付/敏感功能时,请使用此技能。提供全面的安全检查清单和模式。
plankton-code-quality
使用 Plankton 实现编写时代码质量强制执行 —— 通过钩子在每次文件编辑时进行自动格式化、代码检查,并由 Claude 驱动自动修复。
autonomous-loops
自主运行 Claude Code 循环的模式与架构 —— 从简单的顺序流水线到 RFC 驱动的多智能体 DAG 系统。
visa-doc-translate
将签证申请文件(图片)翻译成英文,并创建包含原文和译文的双语PDF
swiftui-patterns
SwiftUI 架构模式,使用 @Observable 进行状态管理,视图组合,导航,性能优化,以及现代 iOS/macOS UI 最佳实践。
swift-protocol-di-testing
基于协议的依赖注入,用于可测试的Swift代码——使用聚焦协议和Swift Testing模拟文件系统、网络和外部API。
swift-concurrency-6-2
Swift 6.2 可接近的并发性 — 默认单线程,@concurrent 用于显式后台卸载,隔离一致性用于主 actor 类型。