Skip to content

feat(plugins): add loopback proxy with scope enforcement and secret stripping - #1728

Open
developerkunal wants to merge 12 commits into
DXCDT-2603/plugin-storefrom
DXCDT-2606/loopback-proxy
Open

developerkunal wants to merge 12 commits into
DXCDT-2603/plugin-storefrom
DXCDT-2606/loopback-proxy

Conversation

@developerkunal

@developerkunal developerkunal commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🔧 Changes

Adds internal/plugins/proxy, which sits between a plugin process and the Auth0 Management API. A plugin never gets the real access token. It gets a random secret for the run and calls a local HTTPS proxy, which swaps in the real token on the calls it decides to forward. Nothing calls the proxy yet, so there is no user visible change.

The proxy listens on 127.0.0.1 on a random port with a certificate made for that run, and a plugin is pointed at it through AUTH0_PLUGIN_DOMAIN and AUTH0_PLUGIN_MANAGEMENT_TOKEN.

Requests are denied by default

  • The bearer secret must match, and the Host header must be the proxy address.
  • Paths must already be canonical and start with /api/v2/. Odd paths are rejected, never repaired, so the path that is checked is the path that is forwarded.
  • Every call must match a rule in the scope table, and one of the scopes the command declared must satisfy it. Otherwise the call gets a 403 that names the missing scope when there is one.
  • Only a few safe headers are forwarded, and the plugin's own Authorization header is dropped.

Responses

  • Secret fields are removed by key name, at any depth, from every JSON response. A response the proxy cannot inspect (non JSON, compressed or too large) is replaced with a 502. So is an upstream redirect, because the token should never be sent anywhere the proxy did not choose.
  • When the tenant answers 401, concurrent calls share one token refresh and the request is retried once. A session that cannot be renewed gives the plugin a session_expired error.

Fail closed. The proxy refuses to start if the registry index does not publish a scope table or a list of secret fields, because forwarding without either would be fail open.

Existing code. In internal/plugins/registry, scopeTable and secretFields were opaque raw JSON. They are now typed and validated. This is a deliberate change: an index with either field in any other shape is now rejected when parsed.

📚 References

DXCDT-2606. Part of the plugin framework stack of 11 PRs, and it builds on the one below it (DXCDT-2603).

🔬 Testing

The new code is covered by unit tests.

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

@developerkunal
developerkunal requested a review from a team as a code owner October 24, 2026 14:47
Comment thread internal/plugins/proxy/proxy.go Resolved
@developerkunal
developerkunal force-pushed the DXCDT-2606/loopback-proxy branch from 9ca63e8 to 172b55b Compare October 24, 2026 15:30
@developerkunal
developerkunal force-pushed the DXCDT-2606/loopback-proxy branch 2 times, most recently from 2063021 to 3460887 Compare November 2, 2026 14:31
@developerkunal
developerkunal force-pushed the DXCDT-2606/loopback-proxy branch from 3460887 to b892768 Compare November 2, 2026 19:37
@developerkunal
developerkunal force-pushed the DXCDT-2606/loopback-proxy branch from b892768 to 1b1d37e Compare November 24, 2026 11:34
@developerkunal
developerkunal force-pushed the DXCDT-2606/loopback-proxy branch from 1b1d37e to b57cd8a Compare November 24, 2026 12:03
@bkiran6398
bkiran6398 force-pushed the DXCDT-2606/loopback-proxy branch from b57cd8a to d2fdcbd Compare November 27, 2026 06:23
@developerkunal
developerkunal removed this pull request from stack #1736 November 30, 2026 17:24
@developerkunal
developerkunal force-pushed the DXCDT-2606/loopback-proxy branch from d2fdcbd to cbad0a2 Compare November 30, 2026 17:24
@developerkunal
developerkunal removed this pull request from stack #1792 November 30, 2026 17:27
…tripping

- Adds internal/plugins/proxy, a per-run HTTPS proxy on 127.0.0.1 that a plugin calls with a per-run secret instead of the real token.
- Denies by default: paths must be canonical and under /api/v2/, methods are allowlisted, and each call must match a rule in the scope table that one of the command's declared scopes satisfies. A denied call gets a 403 that names the missing scope.
- Removes secret fields from every JSON response, rejects responses it cannot inspect, and drops request headers that are not on an allowlist.
- Refreshes the token once for concurrent 401s, caps refreshes per run, bounds in-flight calls, and exposes a one-line summary of the calls it denied.
- Types the scopeTable and secretFields index fields in the registry package with schema validation shared with the proxy.
A call counts as a scope problem only when the proxy denied it or Auth0
answered with the error code insufficient_scope. Every other 4xx answer is
reported as refused by Auth0, with the route, status, error code and message,
and with no advice about scopes. The plugin still receives the answer
unchanged.
The signed index lists the secret fields in two groups. The names under
anywhere are removed at any depth, as before. The paths are removed only where
they match the full path from the root of the response, so a field that is
secret in one place, such as a bind password, no longer removes a harmless
field with the same name elsewhere, such as the password entry under
authentication methods.

The index format version is now 2. The parser refuses version 1 and any
unknown version, and refuses names under anywhere that are too ambiguous to
remove at every depth.
When the proxy removes members from a response it adds the header
X-Auth0-CLI-Stripped with the sorted names of the removed members, so a plugin
can tell a removed field from a missing one. The header never carries values,
is never sent to Auth0, and a header of that name in an answer from Auth0 is
dropped so it cannot be forged.
A 429 answer reaches the plugin with its status, Retry-After and rate limit
headers and its body unchanged, and the proxy never retries it.
The proxy gave the token source a deadline but still waited for it to return,
so a source that never returned held a proxy slot, and for a refresh the
refresh lock, for as long as it hung. The proxy now stops waiting when the
deadline passes and discards whatever the source returns late.
A rule in the signed scope table can list field scopes next to its normal
scopes. A field scope such as read:connections_options allows the routes that
list it and no others, so a plugin that declares it does not gain access to
other routes. The registry also reports which scopes are only field scopes, so
the consent screen can group them.
A path in secretFields may now use ..name to name a member at any depth
below the current position, so a field that sits inside a recursive
structure, such as the params of a nested flow action, is removed at every
level. A path may have at most two descendant steps, may not start with one,
and must name a member that is not ambiguous after the last one.

The registry and the proxy share the same match vectors. The proxy keeps the
match state of every path on the stack of the stripper, so the cost of a body
grows with its size and not with how deeply it is nested.
Policy.KeepSecrets returns a copy of the policy that keeps the members at the given secret paths for one run, while the members below them and every other secret are still removed. The stripper tracks the kept paths with the same automaton, kept members are never listed in X-Auth0-CLI-Stripped, and the index checks every record secret path with the secret path grammar.
@developerkunal
developerkunal force-pushed the DXCDT-2606/loopback-proxy branch from cbad0a2 to 7499266 Compare December 1, 2026 17:11
The wall clock bound failed on slow CI runners. The step count already proves the work stays in proportion to the members.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant