From a7acda1ef5990a3e40fbb2175aa1b096cef10d5e Mon Sep 17 00:00:00 2001 From: Lucy Linder Date: Mon, 2 Jan 2023 09:31:32 +0100 Subject: [PATCH] docs: document how rickrolling works --- README.md | 1 + docs/rickrolling.md | 101 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 docs/rickrolling.md diff --git a/README.md b/README.md index f8cab2c..4931c43 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ as an URL shortener (requires a database)! Learn more at [docs/persistence](docs/persistence.md). To run RickRoller locally or deploy it using Docker, see [docs/quickstart](docs/quickstart.md). +To better understand how the RickRolling works, see [docs/rickrolling](docs/rickrolling.md). ------------- diff --git a/docs/rickrolling.md b/docs/rickrolling.md new file mode 100644 index 0000000..6ff0b5c --- /dev/null +++ b/docs/rickrolling.md @@ -0,0 +1,101 @@ +# How the RickRolling works + + +- [Rick-rolling an URL](#rick-rolling-an-url) +- [How to absolutize URLs (links, images, resources)](#how-to-absolutize-urls-links-images-resources) +- [How to rickroll on user input](#how-to-rickroll-on-user-input) + + +## Rick-rolling an URL + +When this app receives an URL, it: +1. fetches the content using HTTP GET, +2. checks that there are no unsafe redirects to a private IP, +3. absolutizes the URLs found in the HTML, +4. adds some Javascript to trigger a redirection, +5. returns the modified HTML content to be served to the user. + +The interesting points are 3 and 4. + +## How to absolutize URLs (links, images, resources) + +It is common in an HTML page to use *relative URLs* to refer to resources +found on the same server. +This is problematic when rick-rolling: since the page is served by the +rickroll service, relative links will fail. So how can we make those relative +URLs absolute? + +One solution is to parse the file, find the relative URLs and use `urllib.urljoin` +to absolutize them relative to the base URL. Finding all the relative links is however +a big challenge as they can appear in many elements (``, `