spring-security-configurator-auditor

bởi kotlin

Thiết kế và kiểm tra cấu hình Spring Security cho các dịch vụ Kotlin cộng với Spring, bao gồm chuỗi bộ lọc, thiết lập máy chủ tài nguyên JWT hoặc OAuth2, bảo mật phương thức,…

npx skills add https://github.com/kotlin/kotlin-backend-agent-skills --skill spring-security-configurator-auditor

Spring Security Configurator Auditor

Source mapping: Tier 2 high-value skill derived from Kotlin_Spring_Developer_Pipeline.md (SK-13).

Mission

Produce a security model that is explicit, minimal, and testable. Optimize for least privilege and correct failure semantics, not for shortest config.

Read First

  • Current SecurityFilterChain or chains.
  • Endpoint inventory, including actuator, docs, and internal admin routes.
  • Authentication model: session, JWT, OAuth2 resource server, API keys, mTLS, or mixed.
  • Authorization model: roles, scopes, claims, method security, tenant boundaries.
  • CORS, CSRF, and security-related tests.

Design Sequence

  1. Define who the clients are: browser, internal service, public API consumer, job, or operator.
  2. Define authentication mechanism and token trust boundaries.
  3. Enumerate public endpoints explicitly.
  4. Define authorization at URL and method level.
  5. Define 401 and 403 behavior.
  6. Add tests for the critical allowed and denied paths.

Core Security Rules

  • Prefer explicit allowlists for public endpoints.
  • Validate JWT issuer, audience, expiration, signature, and clock-skew assumptions deliberately.
  • Map claims to authorities with a documented rule. Do not assume the default claim mapping is correct for the identity provider.
  • Keep method security and request security aligned. One should not silently compensate for the other.
  • Treat CORS as a policy surface, not a browser nuisance.

Advanced Security Traps

  • Multiple filter chains are ordered. A broad matcher in the wrong chain can shadow a more specific secure chain.
  • permitAll for docs or actuator endpoints often expands further than intended when matchers are too broad.
  • CSRF is not automatically irrelevant just because the app uses tokens somewhere. Browser-based flows and cookie-backed auth change the answer.
  • Async execution, schedulers, and message listeners may not carry the same security context as request threads.
  • Method security on internal helper methods does not help if the call never crosses the proxy boundary.
  • JWT validation without issuer or audience checks is weaker than many teams realize.
  • CORS preflight failures can look like auth failures even when the backend logic is correct.
  • Security behavior differs between servlet and reactive stacks; do not transplant config blindly.

Advanced AuthZ And Token Nuances

  • Path-based authorization is often necessary but rarely sufficient. Tenant, ownership, or resource-state checks may belong in method or domain-level authorization.
  • JWT key rotation, JWKS caching, and clock skew policy are operational concerns as well as security concerns. Token validation must keep working during key rollover.
  • Opaque token introspection, JWT validation, and gateway-terminated auth have different failure modes and trust boundaries. Be explicit about which layer owns what.
  • Custom claim mapping can accidentally drop scopes or elevate privileges if the mapping rule is too permissive.
  • Security headers, session creation policy, and stateless assumptions should match the actual client model rather than copied boilerplate.

Expert Heuristics

  • Model "who can do what to which resource under which tenant or context" before writing matcher code.
  • Prefer deny-by-default designs where new endpoints start closed unless explicitly opened.
  • If browser and machine clients coexist, treat them as separate security surfaces even inside one service.
  • If an endpoint is operationally sensitive but "internal," still secure it explicitly. Internal does not mean safe.

Output Contract

Return these sections:

  • Threat surface: what must be protected and from whom.
  • Authentication model: how identity is established and verified.
  • Authorization model: how access decisions are made.
  • Critical findings or risks: insecure defaults, over-broad rules, missing checks, missing tests.
  • Minimal secure config plan: the smallest safe configuration or patch.
  • Verification: security tests for both allowed and denied access.

Guardrails

  • Do not disable CSRF or frame options without explaining the trust model.
  • Do not rely on default matcher behavior without checking path coverage.
  • Do not leave actuator, Swagger, or internal diagnostics exposed by convenience.
  • Do not generate security config without tests for the key routes.
  • Do not conflate authentication failure with authorization failure.

Quality Bar

A good run of this skill makes the access model explicit and auditable. A bad run produces a working login flow while leaving route exposure, token validation, or test coverage dangerously vague.

Thêm skills từ kotlin

kotlin-backend-jpa-entity-mapping
kotlin
Lớp dữ liệu (data class) của Kotlin rất tự nhiên cho DTO nhưng nguy hiểm cho thực thể JPA. Hibernate dựa vào ngữ nghĩa định danh mà lớp dữ liệu phá vỡ: equals / hashCode trên tất cả các trường làm hỏng tư cách thành viên Set / Map sau khi thay đổi trạng thái, và copy() được tạo tự động tạo ra các bản sao tách rời của các thực thể được quản lý.
kotlin-tooling-agp9-migration
kotlin
Plugin Android Gradle 9.0 khiến các plugin ứng dụng và thư viện Android không tương thích với plugin Kotlin Multiplatform trong cùng một module. Kỹ năng này hướng dẫn bạn thực hiện quá trình di chuyển.
kotlin-tooling-cocoapods-spm-migration
kotlin
Di chuyển dự án KMP từ CocoaPods (kotlin("native.cocoapods")) sang Swift Package Manager (swiftPMDependencies DSL) — thay thế pod() bằng swiftPackage(),…
kotlin-tooling-immutable-collections-0-5-x-migration
kotlin
Di chuyển mã Kotlin (và Java) từ kotlinx.collections.immutable 0.3.x / 0.4.x lên phiên bản 0.5.x mới nhất. Dòng 0.5.x đổi tên mọi phương thức trả về bản sao trên…
kotlin-tooling-java-to-kotlin
kotlin
Chuyển đổi các tệp nguồn Java sang Kotlin tự nhiên bằng phương pháp chuyển đổi 4 bước có kỷ luật với 5 bất biến được kiểm tra ở mỗi bước. Hỗ trợ chuyển đổi nhận biết framework, xử lý các mục tiêu vị trí chú thích, thành ngữ thư viện và bảo toàn API.
kotlin-tooling-native-build-performance
kotlin
Chẩn đoán và khắc phục tình trạng biên dịch và liên kết Kotlin/Native chậm trong các dự án Kotlin Multiplatform nhắm mục tiêu iOS. Sử dụng khi người dùng báo cáo iOS chậm hoặc…
kotlin-spring-proxy-compatibility
kotlin
Diagnose and prevent Kotlin plus Spring proxy failures around `@Transactional`, `@Cacheable`, `@Async`, method security, retry, configuration proxies, and JPA…
ci-cd-containerization-advisor
kotlin
Thiết kế các pipeline build, image và triển khai có thể tái tạo cho ứng dụng Kotlin và Spring, bao gồm xác minh CI, container phân lớp, an toàn khi triển khai,…