Package com.tnsai.server.security
Class OriginPolicy
java.lang.Object
com.tnsai.server.security.OriginPolicy
Origin allowlist for the WebSocket upgrade (TNS-302).
Browsers attach an Origin: <scheme://host[:port]> header on
every cross-origin WS handshake. This handler runs at wsBeforeUpgrade
time and rejects 403 when the supplied Origin is not on the
allowlist.
The default allowlist accepts:
- Missing or
nullOrigin (native non-browser clients). http://localhost:*andhttp://127.0.0.1:*(and thehttps://variants).
with(String...) or
the TNSAI_ALLOWED_ORIGINS environment variable (comma-separated).-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidbefore(io.javalin.http.Context ctx) wsBeforeUpgradehandler.static OriginPolicyfromEnv()ReadsTNSAI_ALLOWED_ORIGINS(comma-separated) and combines it with the loopback default.booleanReturnstruewhenorigin(HTTPOriginheader value) is allowed under this policy.static OriginPolicyloopback()Default policy: accept missing Origin + any loopback host on any port.static OriginPolicyStrict policy: only the explicit origins, no loopback wildcarding.static OriginPolicyPolicy that accepts loopback plus the explicit origin list.
-
Field Details
-
ENV
- See Also:
-
-
Method Details
-
loopback
Default policy: accept missing Origin + any loopback host on any port. -
with
Policy that accepts loopback plus the explicit origin list. -
strict
Strict policy: only the explicit origins, no loopback wildcarding. -
fromEnv
ReadsTNSAI_ALLOWED_ORIGINS(comma-separated) and combines it with the loopback default. Empty / unset env yieldsloopback(). -
explicitOrigins
-
allowLoopback
public boolean allowLoopback() -
isAllowed
Returnstruewhenorigin(HTTPOriginheader value) is allowed under this policy.nullor blank is allowed because non-browser clients omit the header. -
before
public void before(io.javalin.http.Context ctx) wsBeforeUpgradehandler.
-