fix: close stored XSS, anon RPC, and rate limiting gaps in marketplace#32
Merged
fix: close stored XSS, anon RPC, and rate limiting gaps in marketplace#32
Conversation
…tplace - Replace raw innerHTML rendering with sanitize-html (allowlist-based) in plugin detail page — blocks stored XSS via community plugin markdown - Add marketplace/lib/rate-limit.ts: in-memory sliding-window limiter - Rate limit /api/install (5/slug/IP/hr), /api/search (60/IP/min), /api/register (10/IP/hr) with 429 + Retry-After responses - Add migration 00003: REVOKE EXECUTE on increment_install_count from anon + authenticated roles (migration applied to production) - Add *.tsbuildinfo to .gitignore Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Rate limiting must run before authentication so that failed auth attempts increment the counter — otherwise an attacker can brute-force the API key without ever hitting the rate limit. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
Pre-launch security hardening for the marketplace backend. Closes three critical/high findings from the security audit: stored XSS via community plugin markdown rendering, unauthenticated RPC access to inflate install counts, and missing rate limiting across all API routes.
Changes
dangerouslySetInnerHTMLpipeline withsanitize-html(allowlist-based) inapp/plugins/[slug]/page.tsx. Blocks event handlers,<script>tags,javascript:URLs, and all other non-allowlisted content while preserving Tailwind classes for styling.marketplace/supabase/migrations/00003_revoke_anon_rpc.sqlrevokesEXECUTEonincrement_install_countfromanonandauthenticatedroles. Migration already applied to production. The/api/installroute continues to work viaservice_role.marketplace/lib/rate-limit.ts: in-memory sliding-window limiter (Map-based, TTL cleanup). Applied to:/api/install: 5 requests per slug per IP per hour/api/search: 60 requests per IP per minute/api/register: 10 requests per IP per hour429withRetry-Afterheader.gitignore— added*.tsbuildinfo(Next.js incremental build artifact)Test Plan
pnpm build:marketplacepasses with no type errors<img onerror>,<script>,javascript:href, inline event handlersRetry-Afteron N+1Notes
Used
sanitize-htmlinstead ofisomorphic-dompurify(specified in audit plan) —isomorphic-dompurifyhas a known jsdom bundling incompatibility with Next.js App Router wherebrowser/default-stylesheet.csscan't be resolved from the webpack output.sanitize-htmlis the idiomatic server-side choice and has no DOM dependency.Rate limiter is in-process (single-instance safe for launch). When traffic grows, swap for Cloudflare rate limiting rules or Upstash — the interface in
rate-limit.tsis the same either way.Deferred (follow-up PR): search ilike wildcard sanitization, security headers middleware, Tauri CSP,
.env.examplefiles, board server CORS fix.