Loading…
Loading…
Explains the logic for matching a request's dialed endpoint against a backend profile's configured endpoint to authorize credential forwarding.
The CredentialTargetMatch component provides a strict security function to ensure that credentials stored for a specific backend service are only sent to that service's designated endpoint. When the platform makes an outbound request to a backend, this logic compares the endpoint being dialed against the endpoint configured in the backend's profile.
This mechanism prevents accidental or malicious misdirection of sensitive credentials. It operates by parsing and normalizing two endpoint URL strings—one from the profile and one from the live request—and checking if they resolve to the same network location. The comparison is strict: it requires the scheme, hostname, and port to match exactly after normalization.
This check is a worker-side implementation of the same conceptual validation performed by the Admin API's CredentialTargetGuard.
The core logic is encapsulated in the CredentialTargetMatch.sameEndpoint(String profileEndpoint, String dialedEndpoint) method. This method returns true only if both input strings represent the same endpoint target.
The matching process follows these steps:
profileEndpoint and dialedEndpoint strings are independently parsed and normalized into a standardized Endpoint representation consisting of a scheme, host, and port.null, empty, or cannot be parsed into a valid endpoint with a host, the comparison fails, and the method returns false.Endpoint objects are compared for equality.true) only if the normalized scheme, host, and port are identical for both endpoints.The diagram below illustrates the flow of an endpoint string through the normalization process.
flowchart TD
subgraph "Input"
A[Endpoint String]
end
subgraph "Normalization & Parsing"
B{Is string null or empty?}
B -- Yes --> C[Result: No Match]
B -- No --> D[Trim whitespace]
E{Contains "://"?}
D --> E
E -- No --> F[Prepend "https://"]
E -- Yes --> G[Use as-is]
F --> H(Parse as URI)
G --> H
H -- Fails --> C
H -- Succeeds --> I{Host present?}
I -- No --> C
I -- Yes --> J[Normalize Host: toLowerCase()]
K{Scheme present?}
H --> K
K -- No --> L[Default Scheme: "https"]
K -- Yes --> M[Normalize Scheme: toLowerCase()]
N{Port specified?}
H --> N
N -- Yes --> O[Use specified port]
N -- No --> P{Scheme is "http"?}
P -- Yes --> Q[Default Port: 80]
P -- No --> R[Default Port: 443]
end
subgraph "Normalized Endpoint"
S([Scheme, Host, Port])
end
J --> S
L --> S
M --> S
O --> S
Q --> S
R --> SBefore comparison, each endpoint string undergoes a series of normalization steps:
example.com), it is prefixed with https://. If a scheme is present, it is converted to lowercase.http: port 80https: port 443https://example.com/api and https://example.com/ are treated as the same endpoint.IMPORTANT
An empty or null string for either endpoint will always result in a non-match. The system requires both a configured profile endpoint and a dialed endpoint to perform a comparison.
CredentialTargetMatch.sameEndpointCompares two endpoint strings to determine if they refer to the same network destination.
static boolean sameEndpoint(String profileEndpoint, String dialedEndpoint)
| Name | Type | Required | Description |
|---|---|---|---|
profileEndpoint | String | Yes | The endpoint URL configured in the backend profile. |
dialedEndpoint | String | Yes | The actual endpoint URL being contacted for an outbound request. |
Returns true if the normalized scheme, host, and port of both endpoints are identical. Otherwise, returns false.
The following table shows various input pairs and the resulting boolean match status, illustrating the normalization logic.
profileEndpoint | dialedEndpoint | Result | Rationale |
|---|---|---|---|
https://api.example.com | https://API.example.com | true | Host comparison is case-insensitive. |
example.com | https://example.com | true | Missing scheme defaults to https. |
https://example.com | https://example.com:443 | true | Port 443 is the default for https. |
http://example.com:80 | http://example.com | true | Port 80 is the default for http. |
https://example.com/v1 | https://example.com/v2?q=all | true | Path and query parameters are ignored. |
https://example.com | http://example.com | false | Scheme mismatch (https vs. http). |
https://api.example.com | https://data.example.com | false | Host mismatch. |
https://example.com:8443 | https://example.com | false | Port mismatch (explicit 8443 vs. default 443). |
null | https://example.com | false | null input always results in a non-match. |
"" | https://example.com | false | Empty string input always results in a non-match. |
https:// | https://example.com | false | First input has no host, so parsing fails. |
A comparison will return false under any of the following conditions, indicating that credentials should not be forwarded:
https:///path/only).profileEndpoint or dialedEndpoint is null, empty, or contains only whitespace.