Skip to content

feat(studio-local): functions management api - test functions - #42350

Merged
charislam merged 3 commits into
supabase:masterfrom
kallebysantos:feat-local-functions-management-api-4-test-function
Feb 11, 2026
Merged

charislam merged 3 commits into
supabase:masterfrom
kallebysantos:feat-local-functions-management-api-4-test-function

Conversation

@kallebysantos

@kallebysantos kallebysantos commented Jan 31, 2026 •

Copy link
Copy Markdown
Member

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

    • Improved edge function URL validation so testing works reliably both on-platform and off-platform, including proper URL handling for local setups.
  • UI Improvements

    • Moved the Test button in the edge functions interface for more consistent layout while preserving its behavior.
  • Tests

    • Expanded tests to cover platform-aware URL validation scenarios.

@kallebysantos
kallebysantos requested a review from a team as a code owner January 31, 2026 23:25
@vercel

vercel Bot commented Jan 31, 2026

Copy link
Copy Markdown

@kallebysantos is attempting to deploy a commit to the Supabase Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for contributing to Supabase! ❤️ Our team will review your PR.

A few tips for a smoother review process:

  • If you have a local version of the repo, run pnpm run format to make sure formatting checks pass.
  • Once we've reviewed your PR, please don't trivially merge master (don't click Update branch if there are no merge conflicts to be fixed). This invalidates any pre-merge checks we've run.

@vercel

vercel Bot commented Jan 31, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
design-system Ready Ready Preview, Comment Feb 11, 2026 9:07pm
docs Ready Ready Preview, Comment, Open in v0 Feb 11, 2026 9:07pm
learn Ready Ready Preview, Comment Feb 11, 2026 9:07pm
studio-self-hosted Ready Ready Preview, Comment Feb 11, 2026 9:07pm
studio-staging Ready Ready Preview, Comment Feb 11, 2026 9:07pm
ui-library Ready Ready Preview, Comment Feb 11, 2026 9:07pm
zone-www-dot-com Ready Ready Preview, Comment, Open in v0 Feb 11, 2026 9:07pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
cms Ignored Ignored Feb 11, 2026 9:07pm
studio Ignored Ignored Feb 11, 2026 9:07pm

Request Review

@coderabbitai

coderabbitai Bot commented Jan 31, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds 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

Cohort / File(s) Summary
Edge function runtime & validation logic
apps/studio/lib/api/edgeFunctions.ts, apps/studio/pages/api/edge-functions/test.ts, apps/studio/lib/api/edgeFunctions.test.ts
Make URL validation platform-aware by adding isPlatform parameter and local URL regex path when Nimbus prod apex is absent; transform request URL off-platform; update tests to cover platform vs off-platform cases.
UI layout adjustment
apps/studio/components/layouts/EdgeFunctionsLayout/EdgeFunctionDetailsLayout.tsx
Move the "Test" button out of the Popover block into a separate conditional block following the Popover; preserve the onClick behavior and visible condition, but gate telemetry emission by IS_PLATFORM.

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
Loading

Possibly related PRs

Suggested reviewers

  • saltcod
  • aantti
  • awaseem
🚥 Pre-merge checks | ✅ 1 | ❌ 4
❌ Failed checks (3 warnings, 1 inconclusive)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description identifies the PR type (feature) and explains the new behavior (adding test functionality to self-hosted), but is missing required template sections like 'I have read CONTRIBUTING.md', 'What is the current behavior', and 'Additional context'. Complete the PR description template by adding all required sections including the CONTRIBUTING.md acknowledgment and current behavior context.
Linked Issues check ⚠️ Warning The linked issue (API-4) concerns Posthog event tracking documentation standards, which is unrelated to the PR's core objective of enabling edge function testing in self-hosted versions. Link the correct issue that addresses edge function testing functionality in self-hosted Supabase, as the current linked issue covers unrelated documentation review tasks.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Out of Scope Changes check ❓ Inconclusive Changes introducing IS_PLATFORM telemetry gating and platform-aware URL validation are well-aligned with enabling self-hosted function testing. However, the telemetry gating itself relates to API-4's event tracking scope, creating scope ambiguity. Clarify whether the IS_PLATFORM telemetry implementation follows completed API-4 standards, or if API-4 documentation review was a prerequisite for these telemetry changes.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main feature: enabling edge function testing in the self-hosted version. It aligns with the actual changes across multiple files that enable this functionality.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread apps/studio/lib/api/edgeFunctions.ts Outdated
Comment on lines +12 to +18
if (!IS_PLATFORM) {
const regexValidLocalEdgeFunctionURL = new RegExp(
'^https?://[^\\s/$.?#].[^\\s]*/functions/v[0-9]+/.*$'
)

return regexValidLocalEdgeFunctionURL.test(url)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

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.

Comment on lines +24 to +27
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

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.

Suggested change
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.

@aantti aantti added cli Related to supabase/cli self-hosted Related to self-hosted Supabase labels Feb 2, 2026
Comment on lines +308 to +314
sendEvent({
action: 'edge_function_test_side_panel_opened',
groups: {
project: ref ?? 'Unknown',
organization: org?.slug ?? 'Unknown',
},
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only be sending telemetry events on platform

}
})

it('should match valid local edge function URLs', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | 🟡 Minor

Duplicate 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 | 🟡 Minor

Return type mismatch in default case.

The default case returns a raw Response object, but Next.js API routes expect to use res.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` },
+      })

kallebysantos and others added 3 commits February 11, 2026 15:59
…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
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 73.567% (+0.04%) from 73.527%
when pulling 1f91a52 on kallebysantos:feat-local-functions-management-api-4-test-function
into 6168ddc on supabase:master.

@charislam
charislam enabled auto-merge (squash) February 11, 2026 21:14
@charislam
charislam merged commit 70510ac into supabase:master Feb 11, 2026
13 checks passed
@github-actions

github-actions Bot commented Feb 11, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1770845301)

Score Average Improvements Regressions
Completeness 94.4% (-6pp) - 1 🔴
Conciseness 1.4% (+1pp) 1 🟢 -
Docs Faithfulness 55.3% (-3pp) - 1 🔴
Goal Completion 94.4% (-3pp) - 2 🔴
Tool Usage 100% (+0pp) - -
SQL Identifier Quoting 100% (+0pp) - -
SQL Validity 100% (+13pp) 1 🟢 -
Correctness 91.7% (-8pp) - 1 🔴
URL Validity 100% (+0pp) - -
Time_to_first_token 0.21tok (+0.01tok) 7 🟢 5 🔴
Llm_calls 8.28 (+0) 2 🟢 4 🔴
Tool_calls 3.06 (+0.14) 4 🟢 3 🔴
Errors 0 (+0) - -
Llm_errors 0 (+0) - -
Tool_errors 0 (+0) - -
Prompt_tokens 104200.67tok (+16490.17tok) 4 🟢 8 🔴
Prompt_cached_tokens 57187.56tok (+13056tok) 7 🟢 2 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Completion_tokens 5554.5tok (+120.89tok) 5 🟢 7 🔴
Completion_reasoning_tokens 4092.44tok (+128tok) 5 🟢 7 🔴
Completion_accepted_prediction_tokens 0tok (+0tok) - -
Completion_rejected_prediction_tokens 0tok (+0tok) - -
Completion_audio_tokens 0tok (+0tok) - -
Total_tokens 109755.17tok (+16611.06tok) 3 🟢 9 🔴
Estimated_cost 0.02$ (+0$) 5 🟢 7 🔴
Duration 48.17s (+1.09s) 6 🟢 6 🔴
Llm_duration 95.06s (+2.19s) 6 🟢 6 🔴

charislam added a commit that referenced this pull request Feb 18, 2026
…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]>

This branch was successfully deployed

1 active deployment
Preview – learn — 1f91a521 Deployed Feb 11, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli Related to supabase/cli edge functions self-hosted Related to self-hosted Supabase

Projects

Development

Successfully merging this pull request may close these issues.

4 participants