CORS configuration lets your web app safely ask for data from your Supabase backend even if they are on different websites.
CORS configuration in Supabase
cors:
allowed_origins:
- 'https://example.com'
- 'https://another-site.com'
allowed_methods:
- GET
- POST
allowed_headers:
- Content-Type
- Authorizationallowed_origins is a list of website addresses allowed to access your backend.
You can specify which HTTP methods and headers are allowed for security.
https://myapp.com to access your Supabase backend.cors:
allowed_origins:
- 'https://myapp.com'cors:
allowed_origins:
- '*'cors:
allowed_origins:
- 'https://site1.com'
- 'https://site2.com'
allowed_methods:
- GET
- POST
allowed_headers:
- AuthorizationThis configuration allows only https://myfrontend.com to call your Supabase backend using GET and POST requests. It also allows the headers Content-Type and Authorization for these requests.
cors:
allowed_origins:
- 'https://myfrontend.com'
allowed_methods:
- GET
- POST
allowed_headers:
- Content-Type
- AuthorizationAlways restrict allowed_origins to trusted websites to keep your backend safe.
Using '*' for origins allows any website but can expose your backend to risks.
Test your CORS settings by trying to access your backend from different websites.
CORS controls which websites can talk to your Supabase backend.
Set allowed origins, methods, and headers to keep your data safe.
Use specific origins instead of '*' for better security.
Practice
Solution
Step 1: Understand CORS purpose
CORS stands for Cross-Origin Resource Sharing and controls which websites can send requests to your backend.Step 2: Apply to Supabase context
In Supabase, CORS settings define allowed origins that can communicate with your backend securely.Final Answer:
Which websites can access your Supabase backend -> Option BQuick Check:
CORS controls access origins [OK]
- Confusing CORS with database speed
- Thinking CORS changes UI colors
- Assuming CORS affects storage size
Solution
Step 1: Understand allowed origins format
Allowed origins must include the full scheme (https://) and domain to be valid.Step 2: Match correct origin
Only 'https://example.com' matches the requirement exactly; '*' allows all origins, which is insecure.Final Answer:
Set allowed origins to ['https://example.com'] -> Option AQuick Check:
Use full URL with https [OK]
- Using '*' which allows all origins
- Omitting https:// in origin
- Using only domain without scheme
{ allowedOrigins: ['https://app.com'], allowedMethods: ['GET', 'POST'] }, what happens if a browser sends a DELETE request from https://app.com?Solution
Step 1: Check allowed origins
The origin 'https://app.com' is allowed, so origin is not the issue.Step 2: Check allowed methods
Only 'GET' and 'POST' methods are allowed; 'DELETE' is not permitted.Final Answer:
Request is blocked due to method not allowed -> Option DQuick Check:
Method not in allowedMethods [OK]
- Assuming origin blocks the request
- Thinking DELETE is allowed by default
- Believing request is allowed with warning
allowedOrigins: ['https://myapp.com'] but your frontend at https://myapp.com still gets CORS errors. What is the likely mistake?Solution
Step 1: Verify exact origin match
CORS requires exact match including scheme, domain, and port if any.Step 2: Check frontend URL correctness
If frontend URL differs (e.g., with www or port), it must be added exactly in allowedOrigins.Final Answer:
You did not add the frontend URL exactly as it appears -> Option CQuick Check:
Exact origin match needed [OK]
- Assuming '*' fixes errors
- Using http instead of https incorrectly
- Ignoring subdomains or ports in origin
Solution
Step 1: Avoid using '*' for security
Using '*' allows all origins, which is insecure for private apps.Step 2: Specify exact allowed origins
List both 'https://app.example.com' and 'https://admin.example.com' to allow only these trusted sites.Step 3: Use correct scheme https
Use 'https://' to match secure frontend URLs exactly.Final Answer:
allowedOrigins: ['https://app.example.com', 'https://admin.example.com'] -> Option AQuick Check:
List exact secure origins [OK]
- Using '*' which is insecure
- Using only base domain without subdomains
- Using http instead of https
Ready to prove it?
Pass the test and this pattern moves unknown
