TsgcWebSocketFirewallMethods › IsOriginAllowed

IsOriginAllowed Method

Checks a WebSocket Origin header against WebSocketProtection.AllowedOrigins (with wildcard support) and returns whether it is accepted.

Syntax

function IsOriginAllowed(const aOrigin: string): Boolean;

Parameters

NameTypeDescription
aOriginconst stringValue of the HTTP Origin header sent by the client during the WebSocket handshake (e.g. "https://app.example.com").

Return Value

True if the origin is allowed, WebSocketProtection is disabled, or AllowedOrigins is empty; False when the list is populated and the origin does not match any entry. (Boolean)

Remarks

AllowedOrigins entries may include the "*" wildcard, so "https://*.example.com" matches any subdomain. IsOriginAllowed is one of the three granular WebSocketProtection helpers and is invoked automatically by the server integration at handshake time; call it directly only when implementing a custom handshake pipeline.

Example

sgcWebSocketFirewall1.WebSocketProtection.Enabled := True;
sgcWebSocketFirewall1.WebSocketProtection.AllowedOrigins.Add('https://*.example.com');

if sgcWebSocketFirewall1.IsOriginAllowed(Connection.Origin) then
  Accept := True;

Back to Methods