Class HubOrigins
Origin allow-list of HUB-DESIGN.md section 3.6 (R-17), applied by ServerShell once for both WebSocket upgrade paths - Jetty through WSCreator, NIO through WebSocketCommNIO - before any end point constructor is asked. Before B-7b the NIO path tested only that an Origin was present and the Jetty path tested nothing (survey row 65).What is allowed: an Origin whose scheme, host and port match one of
- the server's own domains: the host the request came to (the
Hostheader, whichWSCreatorhas already checked against the URL), and every environment'sallowedDomains, matched byAllowedDomains(exact names and*.wildcards), plus the configured external host name; - the members' public URLs from the hub definition (a Browser page loaded from A connects to B, section 7.5);
- the iiziRun WebView origins
ServerConstants.IIZIRUN_WEBVIEW_ORIGINS, the ones the upload endpoint's CORS filter established; - the definition's
[origins]list, with*.wildcards; - the
$allowedOriginsserver setting (ServerSettings.ALLOWED_ORIGINS): exact origins, no wildcards, for a standalone server that has no definition file to name them in (CC-FIX-SB-CORS).
Host rule: it says the server answers on any name, not that any page may open a WebSocket here.No Origin (ruled H-10): a Browser always sends one, the Java WebSocket client sends none, so members and LicenseComm arrive without one: allowed, and authenticated by what the end point requires. Development (ruled H-10): a refusal is logged at WARNING and not enforced. A literal null origin (a sandboxed page, a data: or file: URL) matches nothing and is refused.
CORS (CC-FIX-SB-CORS, IIZI-JETTY-CORS-CREDENTIALS-ANY-ORIGIN): the same list decides which cross-origin page may read the server's responses, through isAllowedForCORS(String, String): a granted origin is granted, a development server grants the loopback origins as well, and a refusal is enforced on every server, unlike the upgrade of H-10: a CORS refusal is visible at once in the Browser's console.
- Author:
- Christopher Mindus
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordAn origin taken apart: lower-case scheme and host, the port as given or the scheme's default.static enumThe verdict on anOrigin.Field Summary
FieldsConstructor Summary
ConstructorsConstructorDescriptionHubOrigins(Supplier<ServerConfigEnvProps[]> environments, Supplier<String> externalHostName, Supplier<HubDefinition> definition, BooleanSupplier development) Creates the allow-list over live suppliers: nothing is cached, so a reload of the settings or the definition applies at the next upgrade.HubOrigins(Supplier<ServerConfigEnvProps[]> environments, Supplier<String> externalHostName, Supplier<HubDefinition> definition, BooleanSupplier development, Supplier<String> allowedOrigins) Creates the allow-list over live suppliers: nothing is cached, so a reload of the settings or the definition applies at the next upgrade.Method Summary
Modifier and TypeMethodDescriptionDecides on an origin.booleanDecides on an upgrade request and logs a refusal: in production the request is refused, in development it is logged at WARNING and accepted (ruled H-10).booleanisAllowedForCORS(String origin, String requestHost) Decides for CORS whether a cross-origin page may read the server's responses (CC-FIX-SB-CORS,IIZI-JETTY-CORS-CREDENTIALS-ANY-ORIGIN): the allow-list ofcheck(String, String), and on a development server the loopback origins as well (WSHelper.isLoopbackOrigin(String)), so that the pages one development server serves on a developer's machine may call another on another port of it.static StringGets theOriginof an upgrade request from its header fields, whatever the case of the field name: the NIO path lower-cases its names, the Jetty path keeps them.static HubOrigins.OriginoriginOfURL(String url) The origin of a URL, e.g.static HubOrigins.OriginTakes an origin or an absolute URL apart.
Field Details
HEADER
Constructor Details
HubOrigins
public HubOrigins(Supplier<ServerConfigEnvProps[]> environments, Supplier<String> externalHostName, Supplier<HubDefinition> definition, BooleanSupplier development) Creates the allow-list over live suppliers: nothing is cached, so a reload of the settings or the definition applies at the next upgrade. No$allowedOriginssetting.- Parameters:
environments- The server's environments, never null (may answer empty).externalHostName- The external host name URL as configured, or null.definition- The hub definition, null or standalone for none.development- true for a development server.
HubOrigins
public HubOrigins(Supplier<ServerConfigEnvProps[]> environments, Supplier<String> externalHostName, Supplier<HubDefinition> definition, BooleanSupplier development, Supplier<String> allowedOrigins) Creates the allow-list over live suppliers: nothing is cached, so a reload of the settings or the definition applies at the next upgrade.- Parameters:
environments- The server's environments, never null (may answer empty).externalHostName- The external host name URL as configured, or null.definition- The hub definition, null or standalone for none.development- true for a development server.allowedOrigins- The$allowedOriginsserver setting as written, null for none (CC-FIX-SB-CORS).
Method Details
originOf
Gets theOriginof an upgrade request from its header fields, whatever the case of the field name: the NIO path lower-cases its names, the Jetty path keeps them.- Parameters:
headerFields- The header fields, may be null.- Returns:
- The first
Originvalue, stripped, or null for none.
parse
Takes an origin or an absolute URL apart.- Parameters:
origin- The origin as sent, or a URL; may be null.- Returns:
- The parts, or null when it is not
http(s)://host[:port]....
originOfURL
The origin of a URL, e.g. a member's public base URL or the external host name.- Parameters:
url- The URL, may be null.- Returns:
- The parts, or null when invalid.
check
Decides on an origin.- Parameters:
origin- TheOriginheader value, null for none.requestHost- The host the request came to (comm.getDomain()), may be null.- Returns:
- The verdict.
isAllowedForCORS
Decides for CORS whether a cross-origin page may read the server's responses (CC-FIX-SB-CORS,IIZI-JETTY-CORS-CREDENTIALS-ANY-ORIGIN): the allow-list ofcheck(String, String), and on a development server the loopback origins as well (WSHelper.isLoopbackOrigin(String)), so that the pages one development server serves on a developer's machine may call another on another port of it. UnlikeisAccepted(String, String, String, Map), a refusal is enforced on a development server too. Asked byCORSFilterthroughIExternalBrowserPages.isOriginAllowed, for anhttp(s)origin that is neither an iiziRun WebView origin nor the host the request came to, which the filter grants by itself.- Parameters:
origin- TheOriginheader value, null for none.requestHost- The host the request came to, may be null.- Returns:
- true when granted; false for no origin, a foreign origin or the literal
null.
isAccepted
public boolean isAccepted(String who, String uri, String requestHost, Map<String, List<String>> headerFields) Decides on an upgrade request and logs a refusal: in production the request is refused, in development it is logged at WARNING and accepted (ruled H-10).- Parameters:
who- Who the request is from, for the log line, e.g.addr / host.uri- The request URI, for the log line.requestHost- The host the request came to, may be null.headerFields- The header fields, may be null.- Returns:
- true to go on with the upgrade, false to refuse it.