Repository navigation
Conversation
…callers When eRPC runs behind an API gateway or reverse proxy that already authenticates callers, the gateway typically forwards the authenticated client's id in a request header. The new forwardedClientId strategy trusts that header as the user id, so per-client rate-limit budgets, method scoping and the user metric label work without duplicating the gateway's key store in eRPC. The strategy is only active when configured and is offered every HTTP or WebSocket request that carries its header, in declaration order: - header: header name, default X-Client-Id - allowedProxies: only trust the header from these direct TCP peers (the socket address, not the X-Forwarded-For client IP) - allowedIds: optional allowlist, also bounds user label cardinality - rateLimitBudget: budget attached to the authenticated user A header with several values (a proxy that appends instead of overwriting) is rejected, as are ids that are empty, longer than 256 bytes, or contain whitespace, commas or non-ASCII characters. AuthPayload now carries the request headers and remote address so that strategies can read their own transport inputs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Http.ReceivedRequest span recorded r.URL.String() verbatim, so a secret, token or JWT passed as ?secret=, ?token= or ?jwt= was exported to the tracing backend. Replace those values with REDACTED; other query parameters and the path are kept as is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Many clients and gateways use the common "API key" conventions, and some
wallets and SDKs only take a single RPC URL. Let the secret and database
strategies also read the secret from three additional locations, consulted
only when none of the existing ones (?token=, ?secret=,
X-ERPC-Secret-Token, Authorization: Basic) supplied one:
- apikeyQuery: the ?apikey= query parameter
- apikeyHeader: the X-Api-Key or apikey header
- path: the URL path as a single segment, https://host/<secret>, but only
when a domain alias preselects project, architecture and chain so the
path is not used for routing; /admin, /healthcheck and /metrics are
never treated as secrets
Each strategy opts in with additionalLocations (default empty, so existing
setups accept exactly what they did before). A secret found in a location
the strategy does not list is ignored by it. These locations never change
the payload type, so requests that carry none of the existing credentials
still reach a network strategy exactly as before.
NewPayloadFromHttp takes the credential path ("" when the path is
routed). The HTTP handler, WebSocket upgrade check and per-message auth,
and the healthcheck pass it through. A path that carries a secret is
replaced with /REDACTED in the http.url span attribute and in the CORS
metrics' path label, and ?apikey= is redacted like ?secret=.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two opt-in auth additions for deployments where eRPC sits behind an API gateway or is used by clients that only take a single RPC URL, plus a tracing fix found along the way. Nothing changes for existing configurations.
Commits (reviewable separately):
feat(auth):forwardedClientIdstrategy. When a gateway or reverse proxy already authenticates callers and forwards the client id in a header, eRPC trusts that header as the user id, so per-client rate-limit budgets, method scoping and theusermetric label work without duplicating the gateway's key store. Only active when configured.header(defaultX-Client-Id)allowedProxies: only trust the header from these direct TCP peers (socket address, not X-Forwarded-For)allowedIds: optional allowlist, also boundsuserlabel cardinalityrateLimitBudgetfix(tracing): redact?secret=,?token=and?jwt=values from thehttp.urlspan attribute. Today they are exported verbatim to the tracing backend.feat(auth): opt-in secret locations for thesecretanddatabasestrategies, viaadditionalLocations(empty by default). Consulted only when none of the existing locations supplied a secret:apikeyQuery:?apikey=apikeyHeader:X-Api-Key/apikeyheaderpath: the URL path as a single segment (https://host/<secret>), only when a domain alias preselects project, architecture and chain;/admin,/healthcheckand/metricsare never treated as secrets.networkstrategy as before. Unknown location names fail validation./REDACTEDin tracing and in the CORS metrics path label, and?apikey=like?secret=.Security note:
forwardedClientIdtrusts a header. Enable it only behind a proxy that strips or overwrites that header from clients, and restrictallowedProxiesto that proxy.Verification
Based on
erpc/erpcmain @ 094b912.go build ./...,go vet ./...andgofmt -lon touched files are clean.make test-fast(what CI runs): passes, exit 0, no failing test.TestAuthRegistry_SecondarySecretLocations(each location accepted only when listed; standard locations unaffected),TestSecretStrategyConfig_ValidateAdditionalLocations,TestPathSecretAuth_FullyAliasedDomain; plus theforwardedClientIdtests (TestAuthRegistry_ForwardedClientId*,TestAuthStrategyConfig_Validate_ForwardedClientIdRequiresBlock).tygo generate.Notes for review:
forwardedClientIdis inert unless configured, and is only offered requests that carry its header. It authenticates (budgets, method scoping andallowClientDirectivesapply), unliketrustUserIdHeader, which only labels.databasestrategy logsapiKeyat debug/error level, and thesecretstrategy's comparison is not constant-time.forwardedClientId; secret locations with the tracing redaction fix) if reviewers prefer.Docs:
config/auth,operation/tracing.AI assistance
🤖 Generated with Claude Code