Web and API securityHackBlue

CORS and CSP evaluator

Send cross-origin requests to four CORS configurations and run scripts against three Content Security Policies, then see what the browser allows.

  • Interactive lab
  • Intermediate
  • 5 graded steps
  • 0 of 5 solved

Your goal

Your goalFind which server setting leaks data to another site, and which page policy lets an injected script run.

Two browser rules protect https://app.contoso.example. CORS decides whether another site's script can read responses from https://api.contoso.example. Content Security Policy decides which scripts may run on the app's own pages.

Switch between the two evaluators, change the inputs, and read the reason the browser gives for each decision.

What’s on screen
Evaluator
the two buttons at the top. CORS evaluator tests who may read the API. CSP evaluator tests which scripts may run.
CORS controls
Server configuration, Page origin, and Include cookies. Together they describe one cross-site request.
Exchange
the box on the right. It shows the request, the server reply, and the browser’s decision with a reason.
CSP controls
Policy buttons, the parsed directives, and a list of scripts. Each script shows whether it runs.
Walkthrough
the numbered path beside the workbench (below it on a phone). Each step says what to do and what you should see. Hints open one at a time.
Words to know
CORS
cross-origin resource sharing, the browser rule for which sites may read an API
CSP
Content Security Policy, which tells browsers what scripts may run

Server configuration

Page origin

Request

Server codehttps://api.contoso.example
res.set('Access-Control-Allow-Origin', req.headers.origin)
res.set('Access-Control-Allow-Credentials', 'true')
Exchange
// running on https://evil.example
fetch('https://api.contoso.example/account', { credentials: 'include' })

GET /account HTTP/1.1
Origin: https://evil.example
Cookie: session=…

HTTP/1.1 200 OK
Access-Control-Allow-Origin: https://evil.example
Access-Control-Allow-Credentials: true
Content-Type: application/json

Readable. The page at https://evil.example can read the response with the user’s cookies.