fix: throttle writes, bound mcp inputs, harden oauth consent#118
Merged
Conversation
7 tasks
8a5e3ae to
656cd60
Compare
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.
Summary
Task Reference: none (security-review hardening; no associated Mymir task)
Addresses the high/medium findings from the security review that map to hosted-cost abuse and OAuth client spoofing, plus the UI reliability fixes that fell out of the same review (silent mutation failures, delete-undo data loss). Dynamic client registration stays open (the standard MCP onboarding pattern); the fixes target what rides along with it rather than registration itself. All changes are Neon + Cloudflare Workers compatible (no
pg_crondependency — see Notes).Cost / abuse (hosted):
/api/*middleware limiter. The per-IP limb runs before the session lookup so an unauthenticated flood cannot farm free DB session lookups. Team/invite actions carry their own budgets and surface a typedrate_limitedresult./api/mcp(MCP_MAX_BODY_BYTES, streamed with early cancel viareadBodyBoundedso a chunked over-limit body cannot fill isolate memory) plus generous per-field/array ceilings — anti-abuse, not content policy; long unabridged plans still pass. An explicit0hard-freezes the endpoint and logs a warning at module init.MAX_TASKS_PER_PROJECT, default 50k) as a growth backstop, checked race-free under the existing per-project advisory lock; agents hitting it get a dedicatedTaskLimitErrortelling them to stop retrying.sign-in,sign-up,oauth2/register) key on the client IP rather than the unvalidated session cookie — a forged cookie would otherwise mint a fresh bucket per request — and the matcher normalizes trailing slashes so exact-pattern rules cannot be dodged.OAuth consent spoofing:
client_idallowlist (MYMIR_VERIFIED_OAUTH_CLIENT_IDS, empty by default), so an unverified dynamically-registered client renders its raw registered name and cannot impersonate a trusted brand on the consent screen or the devices list. Theverifiedflag is a required parameter onformatOAuthClientNameso no future call site can silently default into brand polish.Agent prompt-injection defense-in-depth:
UI reliability (review fallout, ~half the diff):
StructureViewtoWorkspaceClientso it survives layout remounts (view switches, breakpoint flips, selection transitions) — the stack holds the only copy of a deleted task's body, and remount-scoped state was permanent data loss. The layout was restructured into stable slot components so the element type no longer changes when the selection flips between null and non-null.useUndorejection handling with a generation guard against stale re-pushes) and shows an error in the undo strip; a failed delete keeps the confirm dialog open with a visible error.Type of change
Testing
bun run devbun run lint)bun run typecheck)Notes for reviewer
parseEnvInt(explicit-zero semantics),readBodyBounded(inclusive cap boundary, chunked over-limit reject with stream cancellation), and the verified-client allowlist (memoization re-keys on env change, no test-only reset hook).pg_cronjob to purge abandoned dynamically-registered clients, but Neon does not supportpg_cronand there is no Cloudflare cron trigger configured, so it was dropped. The register rate-limit is the compatible bound on client growth; a Cloudflare Cron Trigger could add active purging later if wanted.lib/api/rate-limit.ts): exact on self-host, a per-isolate soft bound on Workers.content-lengthheader on the reconstructed MCP request (harmless today — runtimes derive length from the byte body).MCP_MAX_BODY_BYTES,MAX_TASKS_PER_PROJECT,MYMIR_VERIFIED_OAUTH_CLIENT_IDS.