An edge function receives a browser request before the application origin. It can route, reject, transform, or cache that request, but it is not automatically a trusted identity source. A viewer can send headers that resemble proxy metadata unless the edge removes them or the origin accepts them only over a protected channel. URL paths may have encoded separators, dot segments, or repeated decoding. Different normalization at edge and origin can make their routing and authorization decisions disagree. The trust contract must say which component establishes client identity, which metadata is edge-authored, and which request bytes reach the origin unchanged.
Edge Request Normalization and Origin Trust
Working case
A permit portal places an edge gate before private case downloads. It checks a path prefix and forwards a tenant header. Reviewer 47 requests an encoded path that the edge treats as public but the origin decodes into a private route. Another request supplies its own tenant header for organization 9. If the origin trusts that header, the edge gate has become a bypass. The revised path is parsed once under a shared canonical rule; the edge removes viewer-supplied internal headers, then forwards a narrow authenticated context over an origin-protected channel. The origin still checks reviewer 47 against the actual case record before returning bytes.
Implementation boundary
function acceptedEdgeContext(context, requestPath, now) {
return context.verified && context.audience === "permit-origin" &&
context.path === requestPath && context.expiresAt > now;
}
console.log(acceptedEdgeContext({ verified: true, audience: "permit-origin", path: "/cases/47", expiresAt: 90 }, "/cases/62", 63));
// Output: falseChoose one canonical URL parser and document whether encoded separators are accepted. Reject ambiguous paths rather than attempting repeated decoding until they look safe. Strip or overwrite internal forwarding headers from every viewer request. If the edge asserts identity or tenant context, bind the assertion to an authenticated channel or signed, short-lived envelope with audience and request scope; do not trust a plain header from the public internet. Keep the origin inaccessible by direct public requests or make it independently verify the assertion and session. Preserve original method, body, and relevant content headers when proxying; an edge transform that changes a signed webhook body can break verification. Test redirects, errors, and range requests under the same policy. Never let a cache hit skip the origin permission check for private representations.
Cost and boundaries
Canonical path parsing is O(L) in path length L and cheap relative to origin work. Signing or verifying an internal envelope adds constant cryptographic cost and key rotation operations. Edge authentication may reduce origin traffic, but duplicating user-permission logic at edge and origin risks drift. A direct origin protection layer adds configuration and incident complexity. Measure rejected ambiguous paths, unauthorized origin attempts, edge-to-origin latency, assertion-verification failures, and the share of requests that still reach the origin. Keep request identifiers bounded in logs so private paths and tokens do not become a second data store.
Failure trace
Send a path with encoded slashes, dot segments, and mixed case where edge and origin could disagree. Both must route to the same policy or reject. Add a viewer-supplied internal tenant header and confirm it is removed before origin handling. Call the origin directly without the expected channel identity and require denial. Replay an edge assertion for a different route and reject its audience or path scope. Return a 403 from origin and verify the edge does not convert it into a cacheable 200. Submit a signed webhook through the proxy and prove the raw body remains verifiable.
Verification
- Viewer-supplied internal headers never become trusted origin context.
- Edge and origin agree on canonical path identity.
- Current record permission remains enforced at origin.
Practice drill
Protect case download 47 for organization 6. Make 63 synthetic requests: valid private reads, forged forwarding headers, ambiguous paths, direct-origin attempts, and old signed envelopes. Compare edge and origin route identities for every case. Remove reviewer 47 from the case after an edge decision and confirm the origin denies the read. Report which component made each decision and the exact bytes used for webhook verification. A valid path through the edge must not imply current record permission.
Decision note
The edge may filter and route, but the origin must trust only protected edge assertions and current authorization state.
Common Mistakes
- Treating an ordinary forwarded header as proof of identity.
- Applying different URL decoding rules in edge and origin.
- Caching a private success before checking its recipient.
Related lessons
Edge Runtime and Origin Boundaries; Edge Compute Budgets and Upstream Fanout; Edge Cache Locality, Invalidation, and Private Scope; Edge-to-Origin Write Routing and Consistency; Outbound URL Requests and SSRF Boundaries; Object-Level Authorization for Reads and Writes.
Apply and check
Build Project: edge permit case delivery and review Web Development: edge and origin contracts quiz.
Further connections
Ingress Proxy and Upstream Contracts; Trusted Proxy Hops and Forwarded Client Identity.
