Repository navigation
Conversation
|
@kallebysantos is attempting to deploy a commit to the Supabase Team on Vercel. A member of the Team first needs to authorize it. |
|
Thanks for contributing to Supabase! ❤️ Our team will review your PR. A few tips for a smoother review process:
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdds platform-aware edge function URL validation and request handling (distinguishes cloud vs self-hosted/local), updates tests for platform context, and repositions the "Test" button in the EdgeFunction details layout without changing its visible condition or onClick behavior. Changes
Sequence Diagram(s)sequenceDiagram
participant UI as "Studio UI"
participant API as "studio/pages/api/edge-functions/test"
participant Validator as "lib/api/edgeFunctions.isValidEdgeFunctionURL"
participant EdgeFn as "Edge Function URL (local or remote)"
UI->>API: POST /api/edge-functions/test { url: requestUrl }
API->>API: compute url = IS_PLATFORM ? requestUrl : replace(public->internal)
API->>Validator: isValidEdgeFunctionURL(url, IS_PLATFORM)
alt valid
API->>EdgeFn: forward test request to url
EdgeFn-->>API: response
API-->>UI: return success
else invalid
API-->>UI: return validation error
end
Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 1 | ❌ 4❌ Failed checks (3 warnings, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@apps/studio/lib/api/edgeFunctions.ts`:
- Around line 12-18: The current non‑platform branch uses
regexValidLocalEdgeFunctionURL which accepts any host and allows SSRF; instead
fetch the configured Supabase origin(s) (e.g., from your app config or env var
like SUPABASE_URL / NEXT_PUBLIC_SUPABASE_URL) and validate the incoming url
against those trusted origins. Concretely, replace the broad regex check with
parsing the url via new URL(url), verify url.origin is one of the
allowedOrigins, and then validate url.pathname with a stricter pattern like
^/functions/v[0-9]+/.*$; update the code around IS_PLATFORM,
regexValidLocalEdgeFunctionURL and the url variable to use this origin-aware
validation.
In `@apps/studio/pages/api/edge-functions/test.ts`:
- Around line 24-27: Validate that process.env.SUPABASE_PUBLIC_URL is defined
and that requestUrl startsWith that value before calling replace; if either
check fails, return an HTTP 400 (bad request) or 500 with a clear error instead
of performing the replace. Update the logic around the destructured req.body and
the computation of url (the variables requestUrl, url, IS_PLATFORM,
SUPABASE_PUBLIC_URL, SUPABASE_URL) to: when IS_PLATFORM is true use requestUrl
unchanged, otherwise assert SUPABASE_PUBLIC_URL exists and
requestUrl.startsWith(SUPABASE_PUBLIC_URL) then construct url by replacing the
prefix with SUPABASE_URL; if validation fails, end the request with an error
response.
| if (!IS_PLATFORM) { | ||
| const regexValidLocalEdgeFunctionURL = new RegExp( | ||
| '^https?://[^\\s/$.?#].[^\\s]*/functions/v[0-9]+/.*$' | ||
| ) | ||
|
|
||
| return regexValidLocalEdgeFunctionURL.test(url) | ||
| } |
There was a problem hiding this comment.
Restrict non‑platform URL validation to trusted origins to avoid SSRF.
This regex accepts any host as long as the path contains /functions/vX, which means the test endpoint can be used to fetch arbitrary URLs in self‑hosted mode. It should validate against the configured Supabase origin(s), not a generic URL shape.
🔒 Suggested hardening (origin-aware validation)
if (!IS_PLATFORM) {
- const regexValidLocalEdgeFunctionURL = new RegExp(
- '^https?://[^\\s/$.?#].[^\\s]*/functions/v[0-9]+/.*$'
- )
-
- return regexValidLocalEdgeFunctionURL.test(url)
+ try {
+ const parsed = new URL(url)
+ const allowedOrigins = [process.env.SUPABASE_URL, process.env.SUPABASE_PUBLIC_URL]
+ .filter((value): value is string => Boolean(value))
+ .map((value) => new URL(value).origin)
+
+ if (allowedOrigins.length > 0 && !allowedOrigins.includes(parsed.origin)) return false
+ return /^\/functions\/v\d+\/.+/.test(parsed.pathname)
+ } catch {
+ return false
+ }
}🤖 Prompt for AI Agents
In `@apps/studio/lib/api/edgeFunctions.ts` around lines 12 - 18, The current
non‑platform branch uses regexValidLocalEdgeFunctionURL which accepts any host
and allows SSRF; instead fetch the configured Supabase origin(s) (e.g., from
your app config or env var like SUPABASE_URL / NEXT_PUBLIC_SUPABASE_URL) and
validate the incoming url against those trusted origins. Concretely, replace the
broad regex check with parsing the url via new URL(url), verify url.origin is
one of the allowedOrigins, and then validate url.pathname with a stricter
pattern like ^/functions/v[0-9]+/.*$; update the code around IS_PLATFORM,
regexValidLocalEdgeFunctionURL and the url variable to use this origin-aware
validation.
| const { url: requestUrl, method, body: requestBody, headers: customHeaders } = req.body | ||
| const url = IS_PLATFORM | ||
| ? requestUrl | ||
| : requestUrl.replace(process.env.SUPABASE_PUBLIC_URL, process.env.SUPABASE_URL) |
There was a problem hiding this comment.
Validate base URL before replacing to prevent malformed or unintended targets.
replace() will no-op if SUPABASE_PUBLIC_URL isn’t a prefix (or is undefined), which can let arbitrary hosts through and produce invalid URLs. Ensure the public URL is present and the request URL starts with it, otherwise return a 400/500.
✅ Safer URL normalization
const { url: requestUrl, method, body: requestBody, headers: customHeaders } = req.body
- const url = IS_PLATFORM
- ? requestUrl
- : requestUrl.replace(process.env.SUPABASE_PUBLIC_URL, process.env.SUPABASE_URL)
+ if (!IS_PLATFORM) {
+ if (!process.env.SUPABASE_PUBLIC_URL || !process.env.SUPABASE_URL) {
+ return res.status(500).json({
+ status: 500,
+ error: { message: 'Missing SUPABASE_PUBLIC_URL or SUPABASE_URL' },
+ })
+ }
+ if (!requestUrl.startsWith(process.env.SUPABASE_PUBLIC_URL)) {
+ return res.status(400).json({
+ status: 400,
+ error: { message: 'Provided URL is not within the configured Supabase public URL' },
+ })
+ }
+ }
+
+ const url = IS_PLATFORM
+ ? requestUrl
+ : requestUrl.replace(process.env.SUPABASE_PUBLIC_URL, process.env.SUPABASE_URL)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const { url: requestUrl, method, body: requestBody, headers: customHeaders } = req.body | |
| const url = IS_PLATFORM | |
| ? requestUrl | |
| : requestUrl.replace(process.env.SUPABASE_PUBLIC_URL, process.env.SUPABASE_URL) | |
| const { url: requestUrl, method, body: requestBody, headers: customHeaders } = req.body | |
| if (!IS_PLATFORM) { | |
| if (!process.env.SUPABASE_PUBLIC_URL || !process.env.SUPABASE_URL) { | |
| return res.status(500).json({ | |
| status: 500, | |
| error: { message: 'Missing SUPABASE_PUBLIC_URL or SUPABASE_URL' }, | |
| }) | |
| } | |
| if (!requestUrl.startsWith(process.env.SUPABASE_PUBLIC_URL)) { | |
| return res.status(400).json({ | |
| status: 400, | |
| error: { message: 'Provided URL is not within the configured Supabase public URL' }, | |
| }) | |
| } | |
| } | |
| const url = IS_PLATFORM | |
| ? requestUrl | |
| : requestUrl.replace(process.env.SUPABASE_PUBLIC_URL, process.env.SUPABASE_URL) |
🤖 Prompt for AI Agents
In `@apps/studio/pages/api/edge-functions/test.ts` around lines 24 - 27, Validate
that process.env.SUPABASE_PUBLIC_URL is defined and that requestUrl startsWith
that value before calling replace; if either check fails, return an HTTP 400
(bad request) or 500 with a clear error instead of performing the replace.
Update the logic around the destructured req.body and the computation of url
(the variables requestUrl, url, IS_PLATFORM, SUPABASE_PUBLIC_URL, SUPABASE_URL)
to: when IS_PLATFORM is true use requestUrl unchanged, otherwise assert
SUPABASE_PUBLIC_URL exists and requestUrl.startsWith(SUPABASE_PUBLIC_URL) then
construct url by replacing the prefix with SUPABASE_URL; if validation fails,
end the request with an error response.
| sendEvent({ | ||
| action: 'edge_function_test_side_panel_opened', | ||
| groups: { | ||
| project: ref ?? 'Unknown', | ||
| organization: org?.slug ?? 'Unknown', | ||
| }, | ||
| }) |
There was a problem hiding this comment.
We should only be sending telemetry events on platform
| } | ||
| }) | ||
|
|
||
| it('should match valid local edge function URLs', () => { |
There was a problem hiding this comment.
Tests are only ever run in !IS_PLATFORM so to maintain testing for both versions, the utility function should accept IS_PLATFORM as a parameter
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
apps/studio/lib/api/edgeFunctions.test.ts (1)
6-11:⚠️ Potential issue | 🟡 MinorDuplicate URL entry in test fixture.
Lines 9 and 10 contain identical URLs:
'https://projectref.supabase.red/functions/v3/hello-world'. This appears to be a copy-paste oversight.🧹 Proposed fix
const validEdgeFunctionUrls = [ 'https://projectref.supabase.co/functions/v1/hello-world', 'https://projectref.supabase.red/functions/v1/hello-world', 'https://projectref.supabase.red/functions/v3/hello-world', - 'https://projectref.supabase.red/functions/v3/hello-world', ]apps/studio/pages/api/edge-functions/test.ts (1)
11-18:⚠️ Potential issue | 🟡 MinorReturn type mismatch in default case.
The default case returns a raw
Responseobject, but Next.js API routes expect to useres.status().json()or similar. This inconsistency could cause unexpected behavior.🔧 Proposed fix using NextApiResponse
default: - return new Response( - JSON.stringify({ data: null, error: { message: `Method ${method} Not Allowed` } }), - { - status: 405, - headers: { 'Content-Type': 'application/json', Allow: 'POST' }, - } - ) + res.setHeader('Allow', 'POST') + return res.status(405).json({ + data: null, + error: { message: `Method ${method} Not Allowed` }, + })
…onURL testable - Wrap sendEvent in EdgeFunctionDetailsLayout with IS_PLATFORM check so telemetry is only sent on the platform, not in self-hosted mode - Accept isPlatform as an explicit parameter in isValidEdgeFunctionURL instead of importing IS_PLATFORM, so tests can exercise both platform and non-platform code paths - Expand test coverage to separately validate platform and local URL acceptance/rejection
31e7ce7 to
1f91a52
Compare
Braintrust eval report
|
…nments (#42992) Feature ## What is the current behavior? The Functions counter on the Home page is only displayed in platform environments. In self-hosted setups, the counter is hidden due to a platform guard, even though Functions may be available. ## What is the new behavior? The Functions counter is now also displayed in self-hosted environments. This is now possible thanks to the following PRs: - #40690 - #42322 - #42349 - #42350 These PRs introduce and enable the API required for listing Functions in Studio, making it feasible to show the Functions count outside of the platform environment. ## Additional context Related issues: #36285 This change removes the platform-only restriction around the Functions card in the Home interface, allowing feature parity between platform and self-hosted deployments where the Functions API is available. --------- Co-authored-by: Andrey A. <[email protected]> Co-authored-by: Charis Lam <[email protected]>
What kind of change does this PR introduce?
Feature
What is the current behavior?
Functions page on self-hosted differs from Platform
What is the new behavior?
Adds the possibility to try/test functions in Self-Host version.
Details
Screen.Recording.2026-01-31.at.23.23.22.mov
Summary by CodeRabbit
Bug Fixes
UI Improvements
Tests