You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Path credential placement matches the whole path literally, so one credential cannot serve an API whose token is a path prefix (e.g. Telegram /bot<token>/<method>) #5757
Since v0.1.8/v0.1.9 a provider credential with auth_style: path is accepted only when the request path, after the credential's placeholder is normalized to {credential}, is byte-for-byte equal to path_template. APIs that put the token in a path prefix and the operation after it — Telegram Bot API (/bot<token>/sendMessage, /bot<token>/getUpdates, …) is the common case — need one credential (and one provider) per method path.
Where
crates/openshell-core/src/secrets.rs@v0.1.9, placement_permits, the CredentialPlacement::PathTemplate arm:
// Normalize only this credential's slot; all other path text must match.
...slots == 1 && normalized == *expected
The upstream test path_placement_checks_exact_slot_and_literal_template (same file, around line 1825) makes it explicit: template /bot{credential}/events accepts /bot<token>/events and rejects /bot<token>/echo with a placement mismatch.
In v0.1.7 there was no placement check, so /bot{credential}/ effectively worked as a prefix.
Reproduction (observed on v0.1.9, Helm chart 0.1.9, Kubernetes driver)
Provider profile with one credential: auth_style: path, path_template: "/anything/x{credential}/", endpoint httpbin.org:443.
From the sandbox: GET https://httpbin.org/anything/x<placeholder>/y.
Result: 403, error: credential_placement_mismatch; the request never reaches the upstream.
The same request to exactly /anything/x<placeholder>/ is resolved and forwarded.
Request
Keep the exact-placement protection (it is the point of #4886) but allow the template to say where the credential may sit without fixing the rest of the path, for example one of:
a trailing wildcard, e.g. path_template: "/bot{credential}/**" (same glob semantics as NetworkEndpoint.path), or
a prefix mode, e.g. path_template_match: prefix, requiring the path to start with the normalized template.
Either keeps "exactly one slot, at this position" while letting /bot<token>/sendMessage and /bot<token>/getUpdates share one credential.
Context
We wrap OpenShell for a multi-tenant agent service; customers register per-service credentials, and per-method credentials for Telegram-style APIs are not practical. For now we document the exact-path behaviour and tell customers to register one credential per path.
Byte equality was buying "this credential can't be replayed against a different path," and segment-anchored matching keeps exactly that property without pinning the whole path — so trailing {rest} it is, not path_prefix. A prefix is replayable by construction; we'd be documenting a footgun instead of not shipping one.
defmatch(template: str, path: str) ->str|None:
t, p=template.split("/"), path.split("/")
ift[-1] =="{rest}":
iflen(p) <len(t): # {rest} consumes one or more, never zeroreturnNoneeliflen(t) !=len(p):
returnNonecaptured=Nonefori, seginenumerate(t):
ifseg=="{rest}":
returncapturedif"{credential}"inseg:
prefix=seg.split("{credential}")[0]
ifnotp[i].startswith(prefix):
returnNonecaptured=p[i][len(prefix):]
elifseg!=p[i]:
returnNonereturncaptured
Splitting on / is what makes %2f the real problem — a raw / can't land in a captured segment, but %2f, %2F and .. can, so validate after matching and before re-interpolation, case-insensitively on the escapes. Same reason host pinning has to survive the path match now, and I'd refuse cross-host redirects outright rather than just pinning the initial request.
On specificity: rank by literal segment count, then template length, and never by registration order — otherwise the first provider to add {rest} eats everyone else's traffic and it looks like a routing bug, not an auth bug.
Log redaction is in scope for the same PR. A token in a path is in every proxy log and nobody notices.
This issue's framing is right, and the trailing-wildcard direction (rather than prefix mode) is the correct one. Four implementation-level points, anchored in the current matcher, that affect the design.
The match already happens on decoded text — decide on that form. In crates/openshell-core/src/secrets.rs, the PathTemplate arm of placement_permits (:512-543) compares slots == 1 && normalized == *expected, where actual is the percent-decoded path: rewrite_uri_path passes RequestCredentialLocation::Path(percent_decode(path)) (:1258), and path_placement_checks_exact_slot_and_literal_template (:1825) pins decode-first by accepting a fully encoded placeholder. So a wildcard will be matched against decoded text, not wire bytes — and non-placeholder segments are forwarded verbatim (:1267-1270), so the matched form and the forwarded form already differ in general. The invariant worth stating: every path a template admits must be the path that reaches upstream, under any normalizer in the chain.
Validate the template when the profile loads, not per request. Grammar: exactly one slot, the slot contained in a single segment, the wildcard only as the final segment and consuming at least one segment. Two slots, an embedded wildcard, or an empty literal becomes a config-load error with a named reason, instead of a traffic-shaped 403 discovered in production.
Constrain what the wildcard captures, on the decoded form. A capture containing a decoded / (from %2f), ./.., or any % should not match. The % rule is the strong one: one decode is all the supervisor can prove; %252f decodes once to a literal %2f and whatever decodes it again upstream is out of scope of the check. Method names and similar identifiers are a conservative charset, so requiring captures to match something like [A-Za-z0-9._~-]+ costs nothing and closes the double-decoding question.
Keep "exactly one slot" meaningful under wildcards. The slot loop (:535-540) pushes other credentials' markers through verbatim; a free capture would let a second credential's marker ride this credential's template. Reject captures containing either marker form (openshell:resolve:env:, OPENSHELL-RESOLVE-ENV-).
Finally, if the wildcard syntax mirrors NetworkEndpoint.path, reuse that matcher rather than growing a second glob implementation, and pin the two together with a differential property test over template×path pairs, including encoded spellings. Exact matching should stay the default: the wildcard is the profile author's explicit statement of scope, which preserves what #4886 bought.
Activity
O96a commentedon Nov 19, 2026
Byte equality was buying "this credential can't be replayed against a different path," and segment-anchored matching keeps exactly that property without pinning the whole path — so trailing
{rest}it is, notpath_prefix. A prefix is replayable by construction; we'd be documenting a footgun instead of not shipping one.Splitting on
/is what makes%2fthe real problem — a raw/can't land in a captured segment, but%2f,%2Fand..can, so validate after matching and before re-interpolation, case-insensitively on the escapes. Same reason host pinning has to survive the path match now, and I'd refuse cross-host redirects outright rather than just pinning the initial request.On specificity: rank by literal segment count, then template length, and never by registration order — otherwise the first provider to add
{rest}eats everyone else's traffic and it looks like a routing bug, not an auth bug.Log redaction is in scope for the same PR. A token in a path is in every proxy log and nobody notices.
yjjnls commentedon Nov 19, 2026
This issue's framing is right, and the trailing-wildcard direction (rather than prefix mode) is the correct one. Four implementation-level points, anchored in the current matcher, that affect the design.
The match already happens on decoded text — decide on that form. In
crates/openshell-core/src/secrets.rs, thePathTemplatearm ofplacement_permits(:512-543) comparesslots == 1 && normalized == *expected, whereactualis the percent-decoded path:rewrite_uri_pathpassesRequestCredentialLocation::Path(percent_decode(path))(:1258), andpath_placement_checks_exact_slot_and_literal_template(:1825) pins decode-first by accepting a fully encoded placeholder. So a wildcard will be matched against decoded text, not wire bytes — and non-placeholder segments are forwarded verbatim (:1267-1270), so the matched form and the forwarded form already differ in general. The invariant worth stating: every path a template admits must be the path that reaches upstream, under any normalizer in the chain.Validate the template when the profile loads, not per request. Grammar: exactly one slot, the slot contained in a single segment, the wildcard only as the final segment and consuming at least one segment. Two slots, an embedded wildcard, or an empty literal becomes a config-load error with a named reason, instead of a traffic-shaped 403 discovered in production.
Constrain what the wildcard captures, on the decoded form. A capture containing a decoded
/(from%2f),./.., or any%should not match. The%rule is the strong one: one decode is all the supervisor can prove;%252fdecodes once to a literal%2fand whatever decodes it again upstream is out of scope of the check. Method names and similar identifiers are a conservative charset, so requiring captures to match something like[A-Za-z0-9._~-]+costs nothing and closes the double-decoding question.Keep "exactly one slot" meaningful under wildcards. The slot loop (:535-540) pushes other credentials' markers through verbatim; a free capture would let a second credential's marker ride this credential's template. Reject captures containing either marker form (
openshell:resolve:env:,OPENSHELL-RESOLVE-ENV-).Finally, if the wildcard syntax mirrors
NetworkEndpoint.path, reuse that matcher rather than growing a second glob implementation, and pin the two together with a differential property test over template×path pairs, including encoded spellings. Exact matching should stay the default: the wildcard is the profile author's explicit statement of scope, which preserves what #4886 bought.