Repository navigation
feat(agent-vault): ask the session's hook, matched by rules - #512
saifsmailbox98 wants to merge 1 commit into
Conversation
|
💬 Discussion in Slack: #pr-review-cli-512-feat-agent-vault-ask-the-session-s-hook-matched-by-rules Posted by Review Police — reviews, comments, new commits, and CI failures will stream into this channel. |
PR overviewThe PR adds rule-based selection of a session’s hook in agent-vault, matching request paths and methods to determine when to invoke it before forwarding requests. Two hook-selection bypasses remain open, with none addressed so far. A session holder can use a percent-encoded path to skip hook approval while the upstream handles the credentialed request as a protected operation. Form-based method overrides can similarly bypass method-specific hooks when the upstream supports method spoofing. Open issues (2)
Fixed/addressed: 0 · PR risk: 7/10 Reviews
|
[Medium impact] The change affects hook decisions across Agent Vault service traffic. Fix the encoded-path bypass and update the required hook guide before merging. Findings
|
| func hookPathMatches(escaped string, prefixes []string) bool { | ||
| return isAmbiguousPath(escaped) || matchesPrefix(escaped, prefixes) |
There was a problem hiding this comment.
Encoded paths skip approval. With a hook rule for
/admin and no service path allowlist, GET /%61dmin skips the hook. isAmbiguousPath accepts %61, and matchesPrefix compares the escaped spelling, while the upstream routes the decoded path to /admin. The proxy still adds the service credential. Check decoded prefixes too, or conservatively ask the hook for escaped paths.
How this was verified: askHook returns without approval when this escaped-path comparison misses, and forward then injects the credential and sends the request.
| // Asked before the credential is attached, for the traffic its rules pick. Nil when the session has none. | ||
| hook *sessionHook |
There was a problem hiding this comment.
Hook guide is outdated.
AGENTS.md still says hooks belong to services and every HTTP or MCP request asks them. The hook now belongs to the session, and unmatched requests skip it. The guide requires updates when a change adds a new convention. Update its hook section to describe the new resolve format and matching rules so future changes follow the right contract.
File Used: AGENTS.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| // The path the agent sent, before substitution. An ambiguous one matches, since the upstream may route it under a | ||
| // listed prefix. | ||
| func hookPathMatches(escaped string, prefixes []string) bool { | ||
| return isAmbiguousPath(escaped) || matchesPrefix(escaped, prefixes) |
There was a problem hiding this comment.
High: Percent-encoded paths bypass hook selection
For a POST rule under /v1/refunds, a session holder can send POST /v1/%72efunds/1: isAmbiguousPath returns false and the escaped-byte prefix comparison fails, so the hook is not called but forward still attaches the credential. An upstream such as Go's ServeMux routes this to /v1/refunds/1, allowing the protected operation without hook approval; compare canonicalized paths, or conservatively select percent-encoded paths as below. (pkg.go.dev)
| return isAmbiguousPath(escaped) || matchesPrefix(escaped, prefixes) | |
| return strings.Contains(escaped, "%") || isAmbiguousPath(escaped) || matchesPrefix(escaped, prefixes) |
| } | ||
|
|
||
| // An override header counts as the method, since a framework that honours it performs the method it names. | ||
| func (r hookRule) matchesMethod(req *http.Request) bool { |
There was a problem hiding this comment.
Medium: Form method overrides bypass hook selection
Against an upstream with form method spoofing enabled, a session holder can send form-encoded POST /items/1 containing _method=DELETE to skip a methods: ["DELETE"] hook: this matcher checks only the wire method and headers, while frameworks such as Laravel route the credentialed request as DELETE. (laravel.com) Upstream method-spoofing configuration isn't available here; conservatively invoke the hook for override-capable form POSTs, or include their effective method in matching before deciding to skip it.
Description 📣
Moves the hook from each service to the session. Resolve now sends one top-level
hookwith rules, and the proxy only asks it for requests a rule matches.methodsandpaths(HTTP, matched on the path before substitution) ortools(MCP, anytools/callin the body, batches included). Postgres, MySQL and SSH match by service name only. No rules means every request goes to the hookhook: { id, name }(nameis null for an inline hook) andsession.metadata; version stays1Companion PR: Infisical/infisical#9697
Type ✨
Tests 🛠️
# Here's some code block to paste some code snippetspackages/cmd/testdata/command_surface.json