feat(media): scope foundation for the media management API#67
Merged
Conversation
Lays the Bearer-key scope model that the upcoming public media CRUD API
(`/api/media/v1/...`) will enforce, without exposing any new route yet.
- migration 010: `cdn_api_keys.scopes text[]` (default `{delivery}`) +
`create_cdn_key_if_allowed` gains a `p_scopes` argument. Existing keys
default to delivery so CDN serving is untouched.
- `validateCDNKey` now surfaces `scopes`; new `requireScope` helper +
`CDN_KEY_SCOPES` (`delivery` | `media:read` | `media:write`).
- DB plumbing (validate select + create insert/RPC) carries scopes; the
CDN key-create route accepts + validates a `scopes` body field.
- `/api/media/` exempted from the session middleware (Bearer-key path,
same pattern as mcp/forms/conversation/cdn).
- `media-ingest.ts`: one SSRF-hardened `fetchRemoteMedia` (MIME + size
enforced). URL-import route refactored onto it; the chat `upload_media`
tool gains the missing SSRF guard.
UI for scope selection (CDNPanel checkboxes) and the public CRUD routes
land in follow-up phases. New error keys (cdn.scope_*, media.url_blocked)
fall back to their key string until added to the dictionary with the UI
strings.
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.
Phase 1 — Media management API foundation (backend only)
REST-first media CRUD API groundwork. No new public route is exposed yet — this lays the scope/key model + shared ingest helper the next phases build on. No user-visible behaviour change beyond a security hardening.
What's in
cdn_api_keys.scopes text[](default{delivery});create_cdn_key_if_allowedgainsp_scopes. Pre-migration keys default to delivery → CDN serving untouched, no key gains media access implicitly.cdn-keys.ts—validateCDNKeysurfacesscopes; newrequireScope(scopes, needed)+CDN_KEY_SCOPES(delivery|media:read|media:write).scopesbody field./api/media/added toPUBLIC_PATHS(Bearer-key path; same pattern as mcp/forms/conversation/cdn).media-ingest.ts— single SSRF-hardenedfetchRemoteMedia(MIME whitelist + size cap). URL-import route refactored onto it; chatupload_mediagains the missing SSRF guard (was fetching arbitrary URLs withoutisAllowedWebhookUrl).Tests
tests/unit/cdn-key-scopes.test.ts(requireScope + scope passthrough/default); existing cdn-keys test updated for the new field. Full suite green: 681.Notes
supabase start+test:rls); PR CI is lint/typecheck/build.cdn.scope_insufficient,cdn.scope_invalid,media.url_blocked) fall back to their key string until added to the dictionary alongside the UI strings (next phase).Next
CDNPanel.vuekey creation + scope badges on the keys list + strings./api/media/v1/{projectId}/assets/...(list/get/upload/update/delete/bulk) +media-url.ts.