Configuring CORS Correctly — Concept Check
Questions on Configuring CORS Correctly. Allow the origins you actually deploy, never a wildcard with credentials, and know why the same config behaves differently in production.
Questions in this quiz
8 questions on Configuring CORS Correctly — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer configures CORS with a wildcard '*' and credentials enabled. What problem will this cause?
- AThe configuration will work only on localhost.
- BThe server will allow all origins, causing a security breach.
- CThe credentials will be ignored by the server.
- DThe browser will reject the configuration due to security risks.
2.Your application works locally but fails in production due to CORS errors. What is a likely cause?
- AThe CORS middleware is not enabled in production.
- BThe allowed origins list only includes localhost.
- CThe production environment uses a different port.
- DThe wildcard '*' is used in production.
3.Why is it important to list both 'https://aicancode.org' and 'https://www.aicancode.org' in the allowed origins?
- AThey are considered different origins by the browser.
- BIt prevents the need for preflight requests.
- CIt allows the use of wildcard origins safely.
- DIt improves the performance of CORS requests.
4.A developer uses regex to match allowed origins: r'https://.*\.aicancode\.org'. What risk does this pose?
- AIt prevents any subdomains from being matched.
- BIt might match malicious subdomains like 'https://evil.com.x.aicancode.org'.
- CIt allows all subdomains, which is secure.
- DIt only matches the exact domain 'https://aicancode.org'.
5.A service in production returns a 500 error before CORS middleware executes. What will the browser report?
- AA successful response with no data.
- BA redirect error due to URL mismatch.
- CA CORS error due to missing headers.
- DA timeout error due to server crash.
6.Why might a CORS configuration that works in staging fail when preview deployments are introduced?
- APreview deployments use a different HTTP method.
- BThe CORS middleware is disabled in preview environments.
- CThe wildcard '*' is used for preview deployments.
- DPreview URLs are not included in the allowed origins list.
7.A developer believes using 'Access-Control-Allow-Origin: *' is safe with cookies. What is the flaw in this belief?
- AIt allows any site to access authenticated responses, which is insecure.
- BIt only works with GET requests, not POST.
- CIt causes performance issues due to excessive requests.
- DIt prevents cookies from being sent with requests.
8.What is a potential issue when a proxy strips CORS headers from requests?
- AThe request will be redirected to a different origin.
- BThe browser will report a CORS error due to missing headers.
- CThe request will fail due to a timeout.
- DThe server will crash due to missing headers.