Class BrowserRequestOriginPolicy
Configure this immutable policy once, then pass it the HTTP method and every raw field occurrence for
Sec-Fetch-Site and Origin. Safe methods are admitted. For other methods,
Sec-Fetch-Site: same-origin and Sec-Fetch-Site: none are sufficient when Origin is absent,
opaque or exactly configured, including when a no-referrer page sends Origin: null. A contradictory
concrete origin rejects. Same-site, cross-site, absent and future syntactically valid fetch-site values require an
exact configured origin. Duplicate or malformed fields reject.
This is a request-origin admission layer, not a complete CSRF defense. Keep application state or synchronizer
tokens where the workflow requires them, validate the request's host at a trusted edge, and do not derive allowed
origins from Host or Forwarded.
- Since:
- 1.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classMutable, non-thread-safe browser-origin policy configuration. -
Method Summary
Modifier and TypeMethodDescriptioncheckResult(@NonNull String method, @NonNull List<@NonNull String> secFetchSiteHeaderValues, @NonNull List<@NonNull String> originHeaderValues) Checks a request without retaining its metadata.toString()Redacts the configured origins and options.withAllowedOrigins(@NonNull Set<@NonNull URI> allowedOrigins) Starts a policy with an exact, complete allowed-origin set.
-
Method Details
-
withAllowedOrigins
public static @NonNull BrowserRequestOriginPolicy.Builder withAllowedOrigins(@NonNull Set<@NonNull URI> allowedOrigins) Starts a policy with an exact, complete allowed-origin set.Origins must use their canonical ASCII serialization: lower-case
httpsscheme and host, no user information, path, query or fragment, and no explicit default port. Plainhttpis rejected unless the development option is enabled, and then is limited to a loopback literal or exactlylocalhost.- Parameters:
allowedOrigins- exact allowed origins- Returns:
- a new builder
- Throws:
NullPointerException- if the set or an entry isnull- Since:
- 1.0.0
-
checkResult
public @NonNull BrowserRequestOriginResult checkResult(@NonNull String method, @NonNull List<@NonNull String> secFetchSiteHeaderValues, @NonNull List<@NonNull String> originHeaderValues) Checks a request without retaining its metadata.The two lists must preserve separate field occurrences. A list with more than one element rejects even if the values are identical. Safe methods (
GET,HEADandOPTIONS) are admitted before request metadata is inspected. Frameworks are responsible for supplying a valid HTTP method token.- Parameters:
method- HTTP methodsecFetchSiteHeaderValues- every rawSec-Fetch-Sitefield occurrenceoriginHeaderValues- every rawOriginfield occurrence- Returns:
- closed admission outcome
- Throws:
NullPointerException- if an input, list entry or method isnullIllegalArgumentException- ifmethodis not a valid HTTP token- Since:
- 1.0.0
-
toString
-