Skip to content
Back to skills

Security Filter Chain

ASecurity

Scaffold a Spring Security 6 SecurityFilterChain @Bean baseline — deny-by-default authorizeHttpRequests, a BCryptPasswordEncoder, explicit CORS, and CSRF guidance (kept for cookie/session auth, disabled only for stateless token APIs). Lambda DSL, Jakarta, no deprecated .and() chaining. Trigger phrases: "set up spring security", "securityfilterchain", "lock down endpoints", "spring security config", "password encoder bean".

  • 10 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added August 31, 2026
developmentgojavaspringapisecurity

Works with

  • api

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned August 31, 2026

npx -y skills add ShipWithAI/shipwithai-plugins --skill security-filter-chain --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Security Filter Chain?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Security Filter Chain
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/shipwithai-security-filter-chain/badge)](https://www.skillsdirectory.com/skills/shipwithai-security-filter-chain)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: security-filter-chain
description: >
  Scaffold a Spring Security 6 SecurityFilterChain @Bean baseline — deny-by-default
  authorizeHttpRequests, a BCryptPasswordEncoder, explicit CORS, and CSRF guidance
  (kept for cookie/session auth, disabled only for stateless token APIs). Lambda DSL,
  Jakarta, no deprecated .and() chaining.
  Trigger phrases: "set up spring security", "securityfilterchain", "lock down
  endpoints", "spring security config", "password encoder bean".
argument-hint: "[base-package]"
---

# Security Filter Chain — Scaffold

Generates a `SecurityConfig` whose authorization is **deny-by-default**, so a new
endpoint is locked until you explicitly open it — the opposite of the permit-all
defaults that trip `sec-missing-method-auth`. See `references/security.md` for the why.

## Step 1 — Detect conventions (do not assume)

Read before generating:
- **Existing security config:** search for a `@Bean SecurityFilterChain` or the legacy
  `WebSecurityConfigurerAdapter`. If one exists, EDIT it (show a diff) — two filter
  chains with overlapping matchers is non-deterministic. If it's the deprecated adapter,
  offer to migrate it to the component-based `SecurityFilterChain` bean.
- **Auth model — pick before generating:**
  - **Cookie/session** (server renders, browser holds a session cookie) → **KEEP CSRF**,
    allow the default `SessionCreationPolicy`.
  - **Stateless token** (JWT/opaque bearer, no cookie) → `SessionCreationPolicy.STATELESS`
    and CSRF disabled (no cookie to forge). Pair with the `jwt-auth` skill.
- **Origins:** find the SPA/mobile origins for CORS; never reflect `*` with credentials.
- **Base package:** mirror existing `config`/`security` packages.

## Step 2 — Render the template

From `assets/SecurityConfig.java.tmpl`, substitute `{{PACKAGE}}` and `{{ALLOWED_ORIGIN}}`
→ `<pkg>/config/SecurityConfig.java`. It provides three beans:
1. `SecurityFilterChain` — `authorizeHttpRequests` ending in `anyRequest().authenticated()`
   (deny-by-default); only health/auth endpoints are `permitAll()`.
2. `PasswordEncoder` → `BCryptPasswordEncoder` (adaptive; never MD5/SHA-1/plaintext —
   `sec-weak-hash`).
3. `CorsConfigurationSource` — explicit origins/methods/headers, `allowCredentials(true)`
   only with exact origins.

## Step 3 — Tune for the chosen auth model

- **Cookie/session:** delete the `.csrf(...).disable()` and `.sessionManagement(...)`
  lines. CSRF protection stays ON. Add a `formLogin`/`httpBasic` or your login flow.
- **Stateless token:** keep both lines; register the bearer filter from `jwt-auth`
  before `UsernamePasswordAuthenticationFilter`.
- Prefer `requestMatchers(HttpMethod.X, "...")` over broad patterns; keep the matcher
  list ordered most-specific first.

## Step 4 — Report

```
Created:
  src/main/java/.../config/SecurityConfig.java
    (deny-by-default authz ✓, BCrypt ✓, CORS ✓, CSRF: <kept|disabled> for <session|token>)
```
State which auth model was chosen and why CSRF is on/off.

## Failure modes — do NOT

- Do NOT leave a wildcard `anyRequest().permitAll()` — that defeats the whole config.
- Do NOT disable CSRF for cookie/session auth (CSRF is exactly that threat model).
- Do NOT set `allowedOrigins("*")` together with `allowCredentials(true)` (forbidden combo).
- Do NOT store passwords with MD5/SHA-1/SHA-256 or plaintext — use BCrypt/Argon2 (`sec-weak-hash`).
- Do NOT use the deprecated `WebSecurityConfigurerAdapter` / `.and()` chaining (Spring Security 6).
- Do NOT add a second SecurityFilterChain bean that overlaps an existing one.

Files in this skill

  • SKILL.md3.5 KB
  • assets/SecurityConfig.java.tmpl3.2 KB
  • evals.json1.8 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.