Sample questions
Question 1Easy
What does CORS let a server do?
- Let chosen other origins read its responses
- Block all requests that come from mobile apps
- Encrypt responses sent to other origins
- Bypass the same-origin policy for its own pages
Answer: A. Let chosen other origins read its responses
Explanation
Cross-Origin Resource Sharing relaxes the same-origin policy for responses, using headers such as Access-Control-Allow-Origin.
Step-by-step solution
- The same-origin policy blocks other origins from reading responses.
- CORS is a server opt-in that relaxes this for chosen origins.
- The server sends headers that name the allowed origins.
- So the correct answer is letting chosen other origins read its responses.
Why the other options are wrong
- B. CORS is a browser rule, not a block on mobile apps.
- C. CORS does not encrypt responses.
- D. CORS does not bypass the policy for the server's own pages; it opens it for other origins.
Tip: CORS is how a server allows specific other origins to read its responses.
Question 2Easy
What is an origin made of?
- Host and path only
- Domain and IP address
- Scheme and path
- Scheme, host and port
Answer: D. Scheme, host and port
Explanation
Two URLs share an origin only if scheme, host and port all match.
Step-by-step solution
- An origin identifies a page by who it came from.
- It is built from the scheme, the host and the port.
- The path is not part of the origin.
- So the correct answer is scheme, host and port.
Why the other options are wrong
- A. Path is not part of the origin, and scheme is missing.
- B. IP address is not part of the origin definition.
- C. The path is left out, and the host is missing.
Tip: Origin = scheme + host + port.
Question 3Easy
Which response header names the origins allowed to read a response?
- Allow
- Access-Control-Allow-Origin
- Content-Security-Policy-Origin
- Origin
Answer: B. Access-Control-Allow-Origin
Explanation
The browser compares this header with the requesting page's origin before exposing the response to JS.
Step-by-step solution
- The browser compares a response header with the page's origin.
- The header that names the allowed origin is Access-Control-Allow-Origin.
- If it matches, the browser lets JavaScript read the response.
- So the correct answer is Access-Control-Allow-Origin.
Why the other options are wrong
- A. Allow is not a CORS response header.
- C. Content-Security-Policy-Origin is not a real CORS header.
- D. Origin is a request header, not the response header that allows reading.
Tip: Access-Control-Allow-Origin is the key CORS response header.
Question 4Easy
Are https://app.example.com and https://api.example.com the same origin?
- Only if they share a server
- Yes, both use HTTPS
- Yes, they share a domain
- No, the hosts differ
Answer: D. No, the hosts differ
Explanation
Different subdomains are different hosts, hence different origins.
Step-by-step solution
- Origin is scheme, host and port.
- app.example.com and api.example.com are different hosts.
- Different hosts make different origins.
- So the correct answer is no, the hosts differ.
Why the other options are wrong
- A. Sharing a server does not make the same origin.
- B. Both using HTTPS is not enough; the hosts still differ.
- C. Sharing a domain is not the same as sharing an origin.
Tip: Subdomains are different origins; CORS is needed between them.
Question 5Medium
A fetch to another origin gets a CORS error in the browser, but the same request works in curl. Why?
- curl uses a different HTTP version that skips CORS
- The browser blocks every request to other origins
- curl ignores CORS; the headers are missing
- The server is down only for browsers
Answer: C. curl ignores CORS; the headers are missing
Explanation
The server responded, but without proper Access-Control-* headers the browser refuses to expose the response to the page.
Step-by-step solution
- Curl does not enforce the browser's CORS rules.
- The server still answers, so the request works in curl.
- The browser blocks the page from reading the response without Access-Control-* headers.
- So the correct answer is that curl ignores CORS and the headers are missing.
Why the other options are wrong
- A. HTTP version does not decide CORS.
- B. The browser does not block every cross-origin request, only unreadable responses.
- D. The server is not down for browsers; it responds without CORS headers.
Tip: A CORS error with curl working means the server is missing Access-Control headers.
Question 6Medium
Which request triggers a preflight?
- A form POST as text/plain
- A PUT with Content-Type: application/json
- A plain GET request with no custom headers
- A GET for an image tag
Answer: B. A PUT with Content-Type: application/json
Explanation
Methods other than GET/HEAD/POST, or JSON content types, or custom headers make a request non-simple.
Step-by-step solution
- Simple requests are GET, HEAD or POST with basic headers and simple content types.
- A PUT is not a simple method.
- Application/json is not a simple content type, so the request is non-simple.
- So the correct answer is a PUT with Content-Type application/json.
Why the other options are wrong
- A. A form POST as text/plain is a simple request, so no preflight.
- C. A plain GET with no custom headers is simple.
- D. An image GET is simple.
Tip: PUT, DELETE, custom headers and application/json trigger a preflight.
Question 7Medium
What is a CORS preflight request?
- An OPTIONS request asking if the real one is allowed
- A HEAD request used to measure network latency
- A request the server sends back to the browser
- A GET request sent to warm up the server cache
Answer: A. An OPTIONS request asking if the real one is allowed
Explanation
For non-simple requests the browser first sends OPTIONS with Access-Control-Request-Method/Headers and waits for permission.
Step-by-step solution
- A preflight is sent before a non-simple cross-origin request.
- It uses the OPTIONS method.
- It asks the server whether the real request method and headers are allowed.
- So the correct answer is an OPTIONS request asking if the real one is allowed.
Why the other options are wrong
- B. HEAD is not used for the preflight.
- C. The server does not send requests to the browser for preflight.
- D. A GET to warm the cache is not a preflight.
Tip: Preflight = OPTIONS sent before the real request.
Question 8Medium
What does Access-Control-Max-Age do?
- Caches the preflight answer for N seconds
- Sets the timeout for the real request
- Sets the cookie lifetime for cross-site requests
- Limits the response body size in bytes
Answer: A. Caches the preflight answer for N seconds
Explanation
Caching the preflight avoids sending an OPTIONS request before every call.
Step-by-step solution
- Preflight responses can be cached by the browser.
- Access-Control-Max-Age gives the cache time in seconds.
- During that time the browser skips the OPTIONS request.
- So the correct answer is caching the preflight answer for N seconds.
Why the other options are wrong
- B. It does not set a timeout for the real request.
- C. Cookie lifetime is not set by this header.
- D. It does not limit the response body size.
Tip: Access-Control-Max-Age cuts repeated OPTIONS requests.
Question 9Hard
Which header lets JavaScript read a custom response header such as X-Total-Count across origins?
- Access-Control-Request-Headers
- Access-Control-Allow-Headers
- Vary
- Access-Control-Expose-Headers
Answer: D. Access-Control-Expose-Headers
Explanation
By default only CORS-safelisted response headers are readable; Expose-Headers adds more. Allow-Headers concerns request headers.
Step-by-step solution
- By default only a few safelisted response headers are readable by JavaScript.
- A custom header such as X-Total-Count is hidden unless exposed.
- Access-Control-Expose-Headers lists the extra headers to expose.
- So the correct answer is Access-Control-Expose-Headers.
Why the other options are wrong
- A. Request-Headers names the request headers, not what is readable.
- B. Allow-Headers concerns request headers the client may send.
- C. Vary changes caching, not header readability.
Tip: Use Access-Control-Expose-Headers to read custom response headers.
Question 10Hard
A server replies to every origin by echoing the request's Origin header with Allow-Credentials: true. What is the risk?
- Browsers will cache responses forever
- There is no risk; this is the recommended setup
- Any website can read users' authenticated data
- Only the server's own pages will be blocked
Answer: C. Any website can read users' authenticated data
Explanation
Reflecting any origin with credentials is effectively a wildcard that lets malicious sites make authenticated reads. Use an allow-list.
Step-by-step solution
- The server echoes any Origin and allows credentials.
- So every website is allowed to read responses with the user's cookies.
- A malicious site can then read authenticated data.
- So the correct answer is that any website can read users' authenticated data.
Why the other options are wrong
- A. Browser caching is not the risk here.
- B. Echoing any origin with credentials is not recommended.
- D. Other sites are not blocked; they are allowed.
Tip: Never reflect any origin with credentials; use an allow-list.
Practise all 13 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →