Bitpath

Lesson 2 · Unit 04

Origins

What an origin is, the same-origin policy, and CORS read as HTTP messages

13 exercisesabout 3 min

What you practise

  • What makes an origin, the same-origin policy, CORS and the preflight read as HTTP messages
  • 16 has the attacks this prevents

Try a question from this lesson

Pick one

You are logged in at bank.example. A page on games.example makes your browser fetch your balance from the bank, and the bank cookie goes along. What must not happen?

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

Origin

An origin is three things together: scheme, host and port. Change any one and it is a different origin.

The path and the query play no part. A port that is not written is the default for the scheme: 443 for https, 80 for http.

https://shop.example:443/cart?x=1

scheme  https
host    shop.example
port    443
origin  https://shop.example

Concept

The same-origin policy

A page may send requests almost anywhere. It may read the responses only from its own origin.

Showing an image or running a script from another origin is allowed: the page uses it without seeing the bytes. Reading a response with fetch needs the other origin to opt in.

Concept

The preflight

Some requests could never come from a plain link or form: a DELETE, a JSON body, an Authorization header.

Before sending one to another origin, the browser asks first with an OPTIONS request, the preflight. The real request follows only if the answer allows it.

OPTIONS /items/7 HTTP/1.1
Origin: https://app.example
Access-Control-Request-Method: DELETE

HTTP/1.1 204 No Content
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: DELETE

9 more exercises in the app

  • 2× type the answer
  • 4× multiple choice
  • 1× fill the blanks
  • 1× true or false
  • 1× match the pairs

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy