spring_boot_starter_security 0.6.2
spring_boot_starter_security: ^0.6.2 copied to clipboard
Spring Security for the web starter: a filter chain configured with HttpSecurity, HTTP Basic, form login, sessions, CSRF, CORS, security headers, JWT resource servers.
0.6.2 #
- feat: 0.6.2 — the theme (typed keys and messages, states, every component, a theme from a URL), (#20)
0.6.1 #
- No changes of its own; released with the family version 0.6.1.
0.6.0 #
Changes #
- Checked against Project Wycheproof's test vectors (Apache-2.0,
test/fixtures/wycheproof/): the JWS verifier on 3 200 ECDSA (ES256, ES384, ES512), RSA PKCS#1 v1.5 (RS256, RS384, RS512), RSA-PSS (PS256, PS384, PS512) and HMAC cases, and the JWK parser and the DPoP proof'sjwkheader on the invalid-curve points of the ECDH vectors: no invalid signature or key is accepted, no valid one is refused. An RSA PKCS#1 signature whose DigestInfo lacks the NULL after the hash OID (Wycheproof'sacceptableMissingNull) verifies, as in pointycastle. - The chain logs its main steps with Spring Security's texts, so
logging.level.root=debugshows what security decides. Debug:Will secure <matcher> with filters: ...(when a chain is built),Securing GET /api/books,Secured GET /api/books,Set SecurityContextHolder to UsernamePasswordAuthenticationToken [Principal=ada, Credentials=[PROTECTED], ...](form, Basic, bearer, DPoP and OAuth 2.0 logins),Failed to process authentication request: Bad credentials,Sending AnonymousAuthenticationToken [...] to authentication entry point since access is denied,Failed to authorize GET /x with ...,Invalid CSRF token found for /login,Changed session id,Logging out [...],Authenticated token(resource server), the DPoP proof accepted or rejected with its reason, the redirect to the provider, the callback received, the ID token validated, the JWK Set fetched. Trace:Invoking <Filter> (n/m),Authorizing GET /x,Checking authorization on GET /x using ...,Set SecurityContextHolder to anonymous SecurityContext, the context stored and retrieved. Nothing at the default level. Never logged at any level: passwords, tokens, DPoP proofs, session ids, CSRF tokens, the signed cookies,code,state,nonce, the PKCE verifier, client secrets,AuthorizationandCookievalues; the credentials of an authentication always show as[PROTECTED], and paths are logged without the query. Values that come from a client go throughLogFormatUtils(line breaks and control characters replaced).test/log_secrets_test.dartruns the heavy scenarios at trace and checks the whole log for every secret they use. - The unreadable-JWK debug line names the exception type only: its message could quote the key.
0.5.0 #
Breaking #
- Access tokens must have the
typJWT(in any case) or none, as Spring Security 7'sJwtTypeValidator.jwt(), in every default decoder and validator (JwtValidators.createDefault,createDefaultWithIssuer, thespring.security.oauth2.resourceserver.jwt.*decoder):at+jwt,logout+jwt,secevent+jwtanddpop+jwttokens signed with the same keys are refused. For a provider that types its access tokens as RFC 9068 says, start the validator withJwtTypeValidator(['at+jwt', 'JWT'], allowEmpty: true). Theoauth2Login()ID token decoder checks the same. - A token bound to a client certificate (
cnf.x5t#S256, RFC 8705) is refused with either scheme: the web starter does not hand client certificates to the security filters, so the binding cannot be checked (Spring refuses it without the certificate too). DefaultBearerTokenResolverwithallowUriQueryParameterreadsaccess_tokeninGETrequests only, as in Spring.- The CORS filter uses only the bean named
corsConfigurationSource, as Spring Security does (another name is ignored; a bean of another type under that name stops the start), andCorsFilter.configurationForreturns aFutureOr. It applies that bean's rules alone where the bean has some:@CrossOriginand theWebMvcConfigurermappings no longer widen them. Elsewhere it applies the rules of the handler the router would call, chosen with itsconsumes,producesandheaderstoo, as Spring'sHandlerMappingIntrospectorchooses it; a WebSocket handshake gets the bean's rules or none, no longer theWebMvcConfigurermappings. - The CORS filter answers a pre-flight that has no configuration with a 200 without CORS headers (was a 403), as Spring's
CorsFilter, and checks an actual request's own method: aHEADorDELETEthe rules do not list is a 403 before the security checks. - Only a login makes a session. Before it, the CSRF token is the
XSRF-TOKENcookie (CookieCsrfTokenRepository,HttpOnly,SameSite=Lax), the page to come back to is the signedREDIRECT_URIcookie (CookieRequestCache, Spring's) and the OAuth 2.0 authorization request ofoauth2Login()the signedOAUTH2_AUTHORIZATION_REQUESTcookie (CookieOAuth2AuthorizationRequestRepository), so clients that are not logged in cannot fill the session store. Spring Security keeps the three in the session;HttpSessionCsrfTokenRepository,HttpSessionRequestCacheandHttpSessionOAuth2AuthorizationRequestRepositorycan still be set. The cookies are signed byCookieSignerwithspring.security.cookie.secret(32 characters or more, the same on every instance), else with a random key of the process. Aresponse_mode=form_postlogin needs HTTPS (its cookie isSameSite=None; Secure). The CSRF token's header is nowX-XSRF-TOKEN(the cookie repository's, as in Spring; it wasX-CSRF-TOKEN); pages that take the name from the token (CsrfToken.headerName) need no change. RequestCache.removeRequesttakes the response too, as in Spring.- A login refused because too many password checks run and wait (
PasswordChecksBusyException,spring.security.password-checks.*) is answered503withRetry-After: 1, never as a failed login (no event, no challenge); a warning is logged at most once a minute. The chain's own provider uses thePasswordCheckLimiterbean. - Each user holds at most 10 sessions by default: a new login ends the user's least recently used one, so one account cannot fill the session store by logging in again and again.
sessionManagement((s) => s.maximumSessions(n))orspring.security.session.maximum-sessionschanges it (-1: no limit, Spring's default),.maxSessionsPreventsLogin(true)orspring.security.session.max-sessions-prevents-login=truerefuses the new login instead (SessionAuthenticationException); the properties are not in Spring Boot, apply only to chains with sessions (form login,oauth2Login()), and a chain's own setting wins. Spring'sSessionRegistry,SessionRegistryImpl(over the session repository: it holds ids only and asks the repository which live),SessionInformation,ConcurrentSessionControlAuthenticationStrategyandRegisterSessionAuthenticationStrategy. Users are told apart by name and by where the login came from. - DPoP: a proof's
jtiis kept untiliat+ clock skew + 5 seconds, so aDPoPProofJtiCachegets anexpiresAt5 seconds later, and must refuse a recorded id until it drops it, whatever its expiry says.
Changes #
- With
oauth2ResourceServer(), a request that carries a token in a header (Authorization: Bearer, orDPoPwith a proof) is exempt from CSRF, as Spring'sregisterDefaultCsrfOverride(which exemptsBeareronly): POST, PUT and DELETE API calls got a 403. A token in theaccess_tokenquery never exempts a request, and the chain's logout and login URLs keep their CSRF check (Spring exempts them). - DPoP: the proof's key is compared with the token's
cnf.jktbefore itsjtiis recorded, so proofs of made-up keys cannot fill the replay cache; a token withoutcnf.jktis refused before the proof is read. - DPoP: a proof can no longer be replayed at exactly
iat+ clock skew. - A DPoP-bound token sent as
Bearerpublishes one failure event, never a success first (UnboundBearerTokenAuthenticationProvider). - A failed fetch of the JWK Set or of the issuer's metadata is made again 30 seconds later at the earliest, never once per token.
- The key cache's lifetime, the refetch pause and the DPoP replay cache's purges are measured on a monotonic clock, so a wall clock set back stretches none of them.
JwtTypeValidator, Spring's validator of thetypheader.StrictHttpFirewallrefuses.and..segments with path parameters (..;x) also withallowSemicolon.oauth2Login(): a callback with another method thanGETor a formPOST(HEAD,PUT, ...) fails withinvalid_requestand leaves the login in progress alone.
0.4.3 #
JwtDecoders.fromIssuerLocationfinds the issuer's metadata with the OAuth2 client's discovery (ClientRegistrations.configurationForIssuerLocation): the same locations and issuer check. A location the fetcher cannot read (a 404 oftransportJwkFetcherincluded) now moves to the next, so the RFC 8414 metadata is found behind a missing OpenID Connect document.oauth2Login()is in the differential test against Spring Security 7.1.oauth2Login(): single sign-on with OAuth 2.0 and OpenID Connect providers (Spring Security'sOAuth2LoginConfigurer,OAuth2AuthorizationRequestRedirectFilter,OAuth2LoginAuthenticationFilter,OidcAuthorizationCodeAuthenticationProvider,HttpSessionOAuth2AuthorizationRequestRepository, the authorized client repositories,OidcClientInitiatedLogoutSuccessHandler); ID token signatures checked with the provider's JWK Set (OidcIdTokenDecoderFactory, also theoidcIdTokenDecoderbean); the default chain logs browsers in through thespring.security.oauth2.client.*registrations. The starter depends on and re-exportsspring_boot_starter_oauth2_client, whoseOAuth2Error,OAuth2AuthenticationException,OAuth2TokenValidator,OAuth2TokenValidatorResultandDelegatingOAuth2TokenValidatorreplace the starter's own (same signatures).defaultSuccessUrl, failure and logout URLs may be absolute (http://localhost:5050/).transportJwkFetcher.
0.4.2 #
- Docs (#9)
0.4.1 #
- feat: guides replace the examples; optional parameters from Dart nullability; coloured logs
- feat: guides replace the examples; optional parameters from Dart nullability; coloured logs
0.4.0 #
- Initial version: Spring Security for
spring_boot_starter_web, secure by default like Spring Boot (every request needs a login; form login for browsers, HTTP Basic for other clients; one user fromspring.security.user.*or a generated password; CSRF, security headers, logout).SecurityFilterChainbeans built withHttpSecurity(authorizeHttpRequestson the router's path patterns, a request no rule matches is denied;httpBasic,formLogin,oauth2ResourceServer,csrf,cors,headers,sessionManagement,exceptionHandling,logout,securityMatcher),FilterChainProxywith aStrictHttpFirewall, sessions with a new id at login, JWT resource servers (RS, PS, ES and HS algorithms on Bouncy Castle's Dart port, JWK sets with key rotation, issuer discovery,spring.security.oauth2.resourceserver.jwt.*), errors asProblemDetailwith Spring's challenges,@AuthenticationPrincipaland@CurrentSecurityContextarguments. Tests:user(),jwt(),csrf(),httpBasic(),anonymous()forMockMvc. Compared with Spring Security 7.1 request by request; the differences are listed in the README.