Skip to content

Agent-ready PasteVault: CLI, sealed shares, secret requests, run, MCP and audit - #260

Merged
dartpain merged 17 commits into
fix/secret-handling-hardeningfrom
feat/agent-ready
Oct 17, 2026
Merged

dartpain merged 17 commits into
fix/secret-handling-hardeningfrom
feat/agent-ready

Conversation

@arc53-machine

Copy link
Copy Markdown
Collaborator

Summary

Makes PasteVault a safe way for AI agents and humans to exchange files, .env files and secrets, and lets an agent use a secret without the secret entering its transcript.

Stacked on #259 (security hardening). Merge #259 first; this PR's base is fix/secret-handling-hardening.

Five features, built in six stages from one design spec. Every stage got an independent adversarial review, and the review findings were fixed before the next stage.

1. Agent-ready CLI basics

  • Input: text and .env pastes in the exact web /p/ format, byte-identical and checked with shared crypto test vectors. Pastes can come from stdin (cat .env | pastevault put -).
  • get: reads /p/ pastes too. It checks metadata first, so a missing key, missing password, sealed share or unwritable output fails before a view is used.
  • Output for agents: --json on every command, with a single error envelope, plus a stable exit-code table (docs/cli-reference.md).
  • Tokens: scoped API tokens (pv_pat_…, stored as SHA-256 hashes, expiring, revocable). Use them with PASTEVAULT_TOKEN or login --with-token, and manage them from the web or with pastevault token.
  • No secrets on the command line: keys and passwords can come from files or environment variables instead of argv. --no-key-in-output keeps the key out of output, and --key-out writes it to a 0600 file.
  • Expiry and views: expiry in minutes (--expires 15m). max_views generalises burn-after-read and is consumed atomically.
  • Commands: list, revoke, status --wait viewed|burned (read receipts) and audit.

2. Agent identities and recipient-bound ("sealed") encryption

  • Agent keys: pastevault agent init creates an X25519 key pair and registers the public key. The fingerprint is pvk1_….
  • Sending to an agent: put --to <agent> (or "Share to agent" on the web) wraps the content key to the agent's public key using PVWRAP1 (X25519 + HKDF-SHA256 + XChaCha20-Poly1305, with the context and recipient fingerprint in the AAD).
  • Links carry no key: a sealed share is useless if leaked, and only the recipient's account and agent can consume it.
  • Pinning: clients pin fingerprints on first use, in the CLI and the browser. A swapped key from a malicious server exits with code 8 or blocks sending in the web UI.

3. Secret request flow (human → agent)

  • Requesting: pastevault request OPENAI_API_KEY --why "run evals" --wait prints https://…/r/ABCD-EFGH#fp=….
  • Answering: the human opens the link while logged in. The page shows Verified key (the request key's fingerprint is recomputed in the browser and compared with #fp) and the agent's reason, marked as untrusted text. The human types the secret or uploads a file, and the browser seals it to the request key.
  • Delivery: the CLI receives it once and stores it in a local store, sealed to the agent key. It returns pv://secret/OPENAI_API_KEY. The server never sees plaintext and wipes the response after delivery.
  • Who can request: only a session, or a token bound to the requesting agent, can create requests. Rate limits, expiry, decline/cancel and audit events are included.

4. pastevault run with .env.pv references

  • References: .env.pv holds KEY=pv://secret/NAME (or share handles).
  • Running: pastevault run --env-file .env.pv -- cmd resolves the references, strips PasteVault's own credentials from the child's environment, forwards signals, and masks secret values in stdout and stderr. Masking covers the raw value plus base64/base64url (at all alignments), hex, every common URL encoding, JSON escaping, and multi-line values. Matches split across writes are still caught.
  • Templates: inject fills template files. get --save stores into the local store.
  • Limits: the docs say plainly that masking keeps secrets out of transcripts; it is not a security boundary.

5. pastevault mcp, a skill and per-tool plugins

  • MCP server: a stdio MCP server built on the official go-sdk. It has nine tools (send_text, send_file, receive, request_secret, request_status, list_secrets, share_status, audit, revoke_share) and no read_secret.
  • What it protects: receive stores secret-like content instead of returning it. File access is limited to the declared roots and refuses credential locations, regardless of case. Sender-chosen names that agents load (.mcp.json, CLAUDE.md, …) are renamed.
  • Elicitation: URL-mode elicitation is used for request_secret when the client supports it.
  • Packaging: a Claude Code plugin with a marketplace, a Codex plugin plus config.toml, a Gemini CLI extension, SKILL.md and an AGENTS.md snippet. The manifests are validated in CI. The plugins were validated and connected with the real claude, codex and gemini CLIs (in a scratch HOME).

6. Read receipts and audit log

  • Events: an AuditEvent table records metadata only: shares created, viewed, burned or revoked, access denied, requests, agents and tokens. IP storage is off by default (AUDIT_IP_MODE, TRUST_PROXY), events have a retention period, and repeat views are coalesced.
  • Where to see it: /account shows per-share activity timelines and an account Activity log. The CLI has status --wait and audit.

Web UI

  • /account: split into Shares (views and sealed badges), Agents, API tokens (each token shown once), Requests and Activity cards.
  • New pages: a "Recipient" select on the home page, and /r/[code].
  • Translations: all 6 locales, with full key parity.

Security hardening found in review (all fixed here)

  • Cross-origin requests: CORS is restricted to trusted origins, and cookie-authenticated mutations with a foreign Origin are rejected (origin_not_allowed).
  • Tokens: an invalid pv_pat_ token gets 401 everywhere, and a token bound to a revoked agent is dead.
  • Relabelled links: a malicious server can't relabel a #k= link as "sealed" to forge content; the CLI refuses before consuming. Non-canonical X25519 keys are rejected in the server, Go and TS. Fingerprint prefixes only resolve to keys that are already pinned.
  • Network: the API client refuses redirects, so credentials are never forwarded. The sign-in return path only allows same-origin targets.
  • Web: browser pins are per origin, so a server can't bypass them by changing the user id. Pages are sent with anti-framing headers.
  • Migrations: pastevault up migrates by default again, and on Postgres it runs migrate deploy before the startup DDL.

Known limitations (documented in docs/security-model.md)

  • Sealed shares give confidentiality to the recipient, but not sender authenticity against a malicious server, which can substitute content. Normal #k= links do protect integrity. Agent-to-agent sender signatures are a possible follow-up.
  • --to-key sealed links, and every sealed share under DISABLE_AUTH, can be consumed (burned) by anyone holding the link, though not decrypted.
  • Masking in run and the MCP no-plaintext policy protect transcripts. An agent with a shell can still read secrets that are injected into processes it controls.
  • The audit log is asserted by the server, not cryptographic. Pins are trust-on-first-use.
  • The macOS and Windows path canonicalisation in the MCP server was compiled and vetted but not run on those platforms. The Firefox masking fallback was tested by simulation only.

Compatibility

  • All API changes are additive: expires_in_hours and burn_after_read still work, and existing #k= links and formats are unchanged.
  • The new CLI works against older servers. Where a feature is missing, it falls back or exits 14.
  • Old CLIs work against the new server, except that they can't open sealed shares.
  • SQLite migrates in place at startup. Postgres has one idempotent migration (20261020_agent_ready), and the CI check covers drift for fresh installs, plain up, and upgrades from Harden burn-after-read, uploads and CLI secret handling #259.
  • DISABLE_AUTH=true: the account, token, agent, request and audit routes return 404, and capabilities report false.

Docs

docs/cli-reference.md (every command, JSON shape and exit code), docs/agents.md (setup for each tool), docs/security-model.md, plus refreshed README.md, CLAUDE.md/AGENTS.md and features.md.

Test plan

  • Go: gofmt, go vet (linux/darwin/windows), go test ./..., go test -race ./..., and cross-compiles for 6 targets
  • npm run typecheck && npm run lint, both root and frontend/
  • npm run test:crypto: shared vectors (paste, chunk, manifest, fingerprint, wrap incl. negatives, request payload) checked by the web code, Go and TS tests
  • node scripts/check-integrations.mjs
  • npm run test:e2e on SQLite: all 7 suites (smoke, tokens, security, cli, agents, requests, mcp)
  • Postgres 16: tests/check-postgres-migrations.mjs (fresh, plain up, upgrade from Harden burn-after-read, uploads and CLI secret handling #259) and the tokens/security/agents/requests suites
  • Headless Chromium checks for every UI flow: token dialog, agents card, share to agent decrypted by the CLI, pin mismatch blocking, /r request answered and delivered and then used through run, tampered or empty #fp blocked, inert reason rendering, clock skew, poll errors, open-redirect payloads, 6 locales, 390 px mobile, dark mode
  • Real harness checks: claude plugin validate --strict, codex mcp list, gemini extensions validate; each server showed as connected
  • Independent adversarial review of each stage; findings fixed in this PR
  • CI on GitHub (new e2e.yml workflow with a Postgres service)

🤖 Generated with Claude Code

https://claude.ai/code/session_01TPmHC7r6snr4Ccq3zga1rk

arc53-machine and others added 15 commits October 16, 2026 14:51
Schema for tokens, agent identities, secret requests and audit events;
session-or-token principal with scopes; personal API tokens; minute
expiry and max_views; audit log; shared route registration.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Text and .env pastes in the web /p/ format, stdin input, get for pastes,
--json and stable exit codes on every command, PASTEVAULT_TOKEN and
login --with-token, key/password from files or env, list/revoke/status/
audit/token commands, shared crypto test vectors, CLI reference and an
e2e CI workflow.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TPmHC7r6snr4Ccq3zga1rk
…cing

- `pastevault up` migrates by default again, before routes create tables;
  SQLite skips the Postgres-only migrations instead of warning
- CORS only answers the server's own and configured origins; cookie
  sessions can't make state-changing requests from untrusted origins
  (403 origin_not_allowed); TRUST_PROXY configures Fastify's trustProxy
- Bad pv_pat_ tokens are rejected on every /api route; tokens bound to a
  revoked agent are invalid and /me hides revoked agents
- Coalesce share.viewed for unlimited shares; enforce the token cap after
  create; roll back shares whose ownership record fails; no-store on
  the owned-share list
- Tests: e2e-security suite, file-share max_views race, Postgres checks
  for plain `up` and the PR1 upgrade path

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TPmHC7r6snr4Ccq3zga1rk
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TPmHC7r6snr4Ccq3zga1rk
Agents API with server-side fingerprints and token binding; shares sealed
to an agent's X25519 key (PVWRAP1) that only the recipient can consume;
CLI agent commands, put --to/--to-key, sealed get, TOFU pins; matching
TypeScript wrap/fingerprint with shared vectors; sealed-share card in the
web viewers.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TPmHC7r6snr4Ccq3zga1rk
- get renames on a clash after opening instead of failing after a view
- bare slug#k= tries pastes first on servers without /meta
- passwords are used as typed; whitespace-only passwords are rejected
- API client refuses redirects so credentials are never forwarded
- paste size checks match the server's request limit; .env falls back to
  a file share when too large; capabilities report paste limits
- token input without echo, token create --out, capability gating for
  account commands, anonymous retry on an invalid token for public reads

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TPmHC7r6snr4Ccq3zga1rk
- get refuses a link carrying a key or password that the server claims is
  sealed, before consuming (prevents server-forged content)
- pvk1_ prefixes only resolve to pinned or local keys
- a token bound to one agent cannot revoke another
- non-canonical X25519 keys and base64url rejected in server, Go and TS
- pins persist only after a successful create; recipient auth on chunk
  downloads of sealed shares; audit denial coalescing keyed by reason
- document that sealed shares do not authenticate the sender

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TPmHC7r6snr4Ccq3zga1rk
Secret-request API (short codes, hashed poll tokens, one-time delivery
with a short re-poll lease, rate limits, expiry, audit); CLI request,
await, fulfil, decline and cancel; a local store sealed to the agent key
with pv://secret handles; run with env injection and output masking;
inject for templates; get --save.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TPmHC7r6snr4Ccq3zga1rk
/account is split into cards under components/account: shares (views as
n/max, sealed badge with the agent name, per-share activity timeline),
agents (fingerprints recomputed locally, pin state, revoke, trust a changed
key), API tokens (new-token dialog that shows the token once, revoke) and the
account activity log with cursor paging. The page is now fully translated.

The home page gains a Recipient select for signed-in accounts with agents.
Sealing to an agent recomputes the fingerprint from the public key, checks it
against a per-account TOFU pin in localStorage (a mismatch blocks sending),
wraps the content key with sealToRecipient, forces one view and no password,
and shows a link without #k plus a `pastevault get <url>` hint. Works for
pastes and file shares; drafts keep the user's own burn/password choices.

The API client no longer sends Content-Type: application/json on bodiless
requests, which made every DELETE (including deleting a tracked share) fail
with 400. All new strings are in the six locales.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TPmHC7r6snr4Ccq3zga1rk
pastevault mcp (stdio, official go-sdk) with send/receive/request/status
tools and no read_secret tool, confined to declared roots and refusing
secret-like plaintext; Claude Code plugin and marketplace, Codex plugin,
Gemini extension, SKILL.md and AGENTS snippet with a manifest check in
CI; docs/agents.md, docs/security-model.md and refreshed README, CLAUDE.md
and AGENTS.md.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TPmHC7r6snr4Ccq3zga1rk
/r/<code> lets the signed-in owner answer an agent's secret request. The page
recomputes the request key's fingerprint and compares it with #fp=:
verified, a blocking mismatch, or a compare-by-eye notice when the link has
none. It shows the requesting agent with this browser's pin state, the reason
strictly as plain text in an "untrusted message" box, and an expiry
countdown. The answer is a masked textarea and/or a file, checked against
max_bytes after encryption, sealed in the browser and posted to fulfill.
The page then polls until the agent collects it, and also offers decline.
It handles the expired, declined, cancelled, delivered and not-found states,
and never stores the value.

The account page gains a Requests card: pending requests link to the page,
recent ones show their status, metadata only.

lib/secret-requests.ts seals the request payload (AAD
pastevault:request:<id>:v1, wrap context request:<id>). A new
request_payload crypto vector section is generated from it; Go checks that
OpenSecretPayload opens it and reproduces the same bytes, and the TS test
re-seals it. All new strings are in the six locales.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TPmHC7r6snr4Ccq3zga1rk
…ening

- creating a secret request needs a session or a token bound to that agent
- masker covers RFC 3986/encodeURIComponent/quote/userinfo escaping in both
  hex cases and multi-line values (LF, CRLF, per line)
- masked run no longer waits on background grandchildren; signals that
  arrive before start are replayed; race-clean and -race in CI
- revoking an agent cancels and wipes its requests; request files survive
  transient errors; await --save-as/--overwrite and collision fallback
- inherited env only resolves pv://secret handles; full fingerprints for
  request fulfil; stricter reason filtering and sanitised CLI output

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TPmHC7r6snr4Ccq3zga1rk
- Sign-in return paths go through lib/redirects.ts: same origin only, no
  backslashes, whitespace or control characters, also once percent-decoded.
  Used by /account, the device page and the /r sign-in link.
- Pins live in one store per origin (pv:pins), matched by agent id or name
  across accounts, so a server that changes the user id can't make a swapped
  key look like a first use. Per-user v1 stores are migrated.
- Browsers without -webkit-text-security keep the textarea, show the value
  with a notice, and never alter it (no single-line password fallback).
- /r keeps the form on a failed refresh, showing an inline "retrying" notice.
  It retries once with backoff, honours Retry-After, and backs off on 429.
- Countdowns use the server clock (Date header offset), and only the server
  decides that a request expired.
- Token dialog: can't be dismissed while creating or while the token is
  shown. The create mutation has gcTime 0.
- Pages send frame-ancestors 'none' and X-Frame-Options: DENY.
- Long names wrap. An empty #fp= blocks. sealedFor is cleared per create.
- Audit labels use a whitelist of known events, and request rows show
  name and code.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TPmHC7r6snr4Ccq3zga1rk
- Paths: deny lists ignore case and trailing dots/spaces; paths are
  re-checked from the opened handle (/proc, F_GETPATH,
  GetFinalPathNameByHandle); reads open with O_NOFOLLOW; .git, harness
  state (~/.claude, ~/.codex, ~/.gemini), CLI credentials, histories and
  key files are refused; home, / and ancestors of home are never roots
  without --allow-home-root.
- receive stages get's output in a private directory and places files
  itself: safe names for sender-chosen names, explicit risky names and
  config/CI/tool directories refused, no symlink following, overwrite only
  of files it wrote this session, default pastevault-received/; save_as
  overwrite only for the same share; only the configured server's shares
  unless --allow-any-host (openWorld).
- Secret-like detector: secret-named keys in dotenv/YAML/JSON/INI,
  spaced KEY = value, case-insensitive PEM, more token prefixes, NFKC and
  homoglyph folding, tokens wrapped across lines.
- requestState bound to its tool and verified for roots responses;
  request_status not read-only, gains wait_seconds (<= 55), per-request
  locking; waits fit client tool timeouts; stdout swap documented.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TPmHC7r6snr4Ccq3zga1rk
…rence

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TPmHC7r6snr4Ccq3zga1rk
@vercel

vercel Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
pastevault Ready Ready Preview Oct 17, 2026 9:27am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ddb7538a-1832-4f92-ac29-1bcc413f27f4

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Roots are stored symlink-resolved, but the early check compared the path
as typed, so on macOS (/var -> /private/var) and Windows (RUNNER~1 short
names) files inside a root were refused. The early check now also
resolves the longest existing prefix of the path before comparing with
the roots and deny lists.

Deny-list entries that do not exist yet (for example ~/.codex/auth.json
under a symlinked home) are resolved the same way, so they still match
once created.

TestCaseInsensitiveRootContainment no longer expects case-sensitive
containment on Windows, where filepath.Rel ignores case.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TPmHC7r6snr4Ccq3zga1rk
Creating the lock file while the previous holder's delete is still
pending fails with ERROR_ACCESS_DENIED on Windows, not "file exists", so
concurrent state updates failed intermittently
(TestConcurrentStateUpdatesPreserveRollbackSkip on windows-latest).
Treat it like a held lock and retry until the deadline.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TPmHC7r6snr4Ccq3zga1rk
@dartpain
dartpain merged commit 8167327 into fix/secret-handling-hardening Oct 17, 2026
15 checks passed
dartpain added a commit that referenced this pull request Oct 17, 2026
Agent-ready PasteVault: CLI, sealed shares, secret requests, run, MCP and audit (#260 → main)

This branch was successfully deployed

1 active deployment
Preview — 9581f418 Deployed Oct 17, 2026 by vercel[bot]
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.

2 participants