One Missing Anchor, One Flickr XSS
Flickr's mobile site loaded page content from a URL fragment, validated it with an unanchored regex that only checked if the hostname appeared somewhere, and rendered the fetched response as HTML. An attacker could host a page that passed the check and, because CORS allowed the cross-origin fetch, inject script into m.flickr.com.
medium.com
Published on medium.com
Bug Bounty
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
Flickr's mobile site, m.flickr.com, was built as a single-page application of its era. Navigation state lived in the URL fragment (location.hash), and JavaScript fetched the matching page over AJAX and swapped the result into the current document. The fragment therefore acted as a routing instruction: change the hash, and the loader would go and retrieve the page that the hash pointed at.
Because the loader was going to fetch a URL taken from the fragment and then render the response as HTML inside m.flickr.com, it needed to be certain that the URL stayed on its own origin. That check is the whole subject of this case. Jack Whitton documented the bug in December 2013 in Abusing CORS for an XSS on Flickr, and the analysis below follows that post.

AI-generated illustration
Setup
No accounts, roles, tool versions or special tooling are described. The preconditions that matter are properties of the target and of the browser:
- The mobile site reads a path out of the URL fragment and fetches it with AJAX.
- The fetched markup is inserted into the page with
innerHTML, so it is parsed and executed as HTML in Flickr's origin. - The browser supports CORS, so a cross-origin AJAX request can complete when the remote server returns the right response headers.
- The attacker controls a server, and therefore controls the headers that server sends.
Delivery is a crafted link whose fragment points at attacker-controlled content, so nothing has to be hosted on Flickr itself.
Finding it
The loader performed two checks before fetching. First, it ensured the path began with a slash. Second, it ran a regular expression meant to confirm that the target was m.flickr.com.
The regex was not anchored to the start of the string. It therefore asked only whether the hostname appeared somewhere in the URL, not whether the URL's host was that hostname. Any URL that merely contained m.flickr.com as a substring passed the check.
The leading-slash rule had a matching gap. A protocol-relative URL beginning with a double slash satisfies "starts with a slash" while pointing at a completely different host.
On its own, a cross-origin AJAX request would simply fail in a browser without CORS, so the flaw could easily have looked harmless. CORS changes that: the browser will complete the request if the remote server opts in with the appropriate response headers, and the attacker owns the remote server and sets its headers. The fetched markup was then written into the page with innerHTML, so it executed in Flickr's origin.
Exploitation
The report deliberately omits reproduction details and payloads, so the steps below describe the mechanism rather than giving a working URL.
Step 1: Put a foreign URL in the fragment
The attacker crafts a link whose fragment carries a URL pointing at attacker-controlled content. Two shapes defeat the two checks:
- A URL that contains
m.flickr.comsomewhere in the string, which satisfies the unanchored regex without the host being m.flickr.com. - A protocol-relative URL starting with
//, which satisfies the leading-slash rule while resolving to a different host.
Step 2: Let the loader fetch it
The victim opens the link. The loader reads the fragment, applies its two checks, both pass, and it issues an AJAX request to the attacker's server. Because the attacker's server returns CORS headers permitting the request, the browser completes it instead of blocking it.
Step 3: Render the response as HTML
The response body, which the attacker fully controls, is written into the page with innerHTML. The markup is parsed in the context of m.flickr.com, so any script in it runs in Flickr's origin.
Root cause
Two validation mistakes combine with one rendering decision:
- Unanchored regex. A substring match on the raw URL string is not origin validation. The check should have compared the resolved origin exactly, not searched for the hostname inside the text.
- Leading-slash check without rejecting
//. A protocol-relative URL begins with a slash but names its own host, so the rule that was meant to keep the path local did not. innerHTMLon fetched markup. Even with a correct origin check, treating a fetched response as trusted HTML means any mistake upstream becomes script execution.
Before CORS, a cross-origin AJAX request would simply fail, so the flaw might have looked harmless. The attacker's server opts in with response headers, so the browser is willing to hand the response to the page.
Impact
The source post does not detail impact. The reasonable assessment is the standard one for XSS: script running in m.flickr.com's origin can act as the logged-in user, reading whatever the mobile site shows them and performing the actions that user could perform. Delivery requires only a crafted link, because the fragment carries the URL that drives the fetch.
Fix
Flickr fixed the issue by anchoring the regex and adding a separate check that rejects double-slash URLs, as Whitton describes. The report does not give the exact patched code.
Defence in depth, as analysis rather than a record of what Flickr shipped:
- Parse, then compare. Use the URL parser and compare the resolved origin exactly; never regex-match raw strings.
- Prefer route names over URLs. Map fragment values to an internal route table so arbitrary hosts never enter the fetch.
- Do not render fetched HTML with
innerHTML. Return data and build the DOM safely, or sanitise with a vetted library. - Add a strict Content Security Policy. Restrict
connect-srcto your own origin so the browser refuses foreign fetches even if validation regresses.
A route table and a parser-based resolver, as a suggested remediation:
const ROUTES = new Set(["/photos", "/explore", "/groups", "/settings"]);
function resolveFragment(hash) { const raw = decodeURIComponent(hash.replace(/^#/, "")); let url; try { url = new URL(raw, window.location.origin); // handles "//host" too } catch { return null; } if (url.origin !== window.location.origin) return null; // exact match const base = "/" + url.pathname.split("/")[1]; return ROUTES.has(base) ? url.pathname + url.search : null;}async function loadPage(hash) { const path = resolveFragment(hash); if (!path) return showNotFound(); const data = await fetch(path, { credentials: "same-origin" }).then(r => r.json()); renderSafely(data); // DOM APIs, no innerHTML}
The resolver parses the fragment against the current origin, which normalises protocol-relative input, then rejects anything whose resolved origin differs. Surviving paths must match a known route, and the loader fetches JSON with same-origin credentials and renders it through DOM APIs rather than innerHTML.
Variants to test
- Unanchored hostname checks elsewhere. Look for client-side validation that tests
url.includes(host)or an unanchored regex. A positive result is a URL whose host is not the target but whose string contains the target hostname, still being fetched. - Protocol-relative input. Try
//attacker.example/...wherever a path is expected. A positive result is a request that leaves the origin despite a leading-slash rule. - Fragment-driven fetches. Find single-page apps that read a URL from
location.hashand fetch it. A positive result is a request to a host you control, triggered purely by the fragment. - CORS-permissive attacker servers. Serve permissive CORS headers from your test server and watch whether the browser completes the cross-origin fetch. A positive result is a response body reaching the page instead of a CORS error.
innerHTMLsinks after fetch. Trace what happens to fetched markup. A positive result is attacker-controlled markup being parsed and executed in the target origin.- CSP
connect-srccoverage. Check whether a policy restricts outbound fetches to the site's own origin. A positive result is a foreign fetch succeeding where the policy should have blocked it.
What happened, in plain words
Flickr is a photo-sharing website. In 2013 it had a separate mobile version at m.flickr.com, built as a single-page application. That means the browser loads one page once, and then JavaScript swaps new content in and out as you move around, instead of loading a fresh page from the server each time.
That mobile site kept track of where you were by reading a piece of the web address called the fragment, the part after the # sign. JavaScript then fetched the matching page in the background and dropped it into the page you were looking at. The fragment was effectively an instruction: change it, and the site would go and get whatever page it pointed at.
Because the site was going to fetch a web address taken from the fragment and then display the result as HTML inside m.flickr.com, it had to be sure that address stayed on its own website. The check it used for that is the whole subject of this case. Jack Whitton wrote the bug up in December 2013 in a post called Abusing CORS for an XSS on Flickr, and everything below follows his account.

AI-generated illustration
A quick word on the two big terms before we go further, because they carry the story.
XSS (cross-site scripting) is when an attacker gets their own code to run inside someone else's website, in the browser of a real visitor. Think of it like slipping a forged page into a printed newspaper: readers think they are reading the paper, but the words are the attacker's. Code running inside a site can do what that site can do for the logged-in user.
CORS (Cross-Origin Resource Sharing) is a set of rules browsers follow when one website's code asks for data from a different website. By default the browser refuses, because letting any site read any other site's data would be chaos. But the other website can send back special response headers saying "it is fine, let this one through". CORS is the mechanism that lets that permission be granted.
Setup
The write-up does not describe any accounts, roles, tool versions or special tooling. What matters are four properties of the target and the browser:
- The mobile site reads a path out of the URL fragment and fetches it with AJAX.
- The fetched markup is inserted into the page with
innerHTML, so it is parsed and executed as HTML in Flickr's origin. - The browser supports CORS, so a cross-origin AJAX request can complete when the remote server returns the right response headers.
- The attacker controls a server, and therefore controls the headers that server sends.
Let us unpack those four, because each one is a beginner-sized idea.
AJAX is the technique a page uses to ask a server for more data in the background, without reloading the whole page. When you scroll a feed and new posts appear, that is usually AJAX. The page's JavaScript sends a request, waits for the answer, and puts the answer on screen.
The URL fragment is the bit of a web address after the #. On a normal page it often points to a section heading. On a single-page app it can be used as a navigation instruction, because changing it does not reload the page but the JavaScript can notice the change and react.
innerHTML is a property in JavaScript that lets code set the contents of an element on the page by handing it a string of HTML. The browser then parses that string as real HTML, which means any tags in it, including script tags, are treated as live markup. It is the difference between handing someone a printed recipe and handing them a loaded oven: the string is not just text, it is instructions the browser will follow.
Origin is the combination of protocol, host and port, for example https://m.flickr.com. Two pages share an origin only if all three match. The browser uses origin as the boundary for what one site's code is allowed to touch on another site.
A response header is a small piece of metadata a server sends back alongside the actual content, like the label on a parcel. CORS permission is expressed in those headers, which is why the attacker controlling their own server matters: they get to write the label.
The delivery vector is a crafted link. The fragment carries the URL that drives the fetch, so nothing has to be hosted on Flickr itself. In plain terms: the attacker only needs to get a victim to click a link, and the malicious content travels inside the link itself.
Finding it
The loader performed two checks before fetching. First, it ensured the path began with a slash. Second, it ran a regular expression meant to confirm that the target was m.flickr.com.
A regular expression (regex) is a pattern used to search text. It is like a very precise find-and-replace rule: you describe a shape of text, and the regex tells you whether a string contains something matching that shape. The catch is that a regex only checks what you tell it to check, and if you describe the shape too loosely, it will happily match things you did not intend.
The regex was not anchored to the start of the string. Anchoring means pinning the pattern to a fixed position, usually the beginning or the end of the text. An unanchored pattern can match anywhere inside the string, like a security guard who checks whether the word "staff" appears anywhere on a badge rather than whether the badge starts with it. The regex therefore asked only whether the hostname appeared somewhere in the URL, not whether the URL's host was that hostname. Any URL that merely contained m.flickr.com as a substring passed the check.
The leading-slash rule had a matching gap. A protocol-relative URL is a web address that starts with // and no protocol, so the browser fills in the protocol from the current page. It begins with a slash, so it satisfies "starts with a slash", but it names its own host, so it points at a completely different website. It is like a rule saying "all deliveries must start with our street name" that is defeated by an address starting with our street name followed by a comma and a different city.
On its own, a cross-origin AJAX request would simply fail in a browser without CORS, so the flaw could easily have looked harmless. CORS changes that: the browser will complete the request if the remote server opts in with the appropriate response headers, and the attacker owns the remote server and sets its headers. The fetched markup was then written into the page with innerHTML, so it executed in Flickr's origin.
That last sentence is the heart of it. The attacker's server says "yes, share this with m.flickr.com", the browser believes it, the response arrives, and the site pastes it into its own page as HTML. The code is now running as if Flickr had written it.
Exploitation
The report deliberately omits reproduction details and payloads, so the steps below describe the mechanism rather than giving a working URL.
Step 1: Put a foreign URL in the fragment
The attacker crafts a link whose fragment carries a URL pointing at attacker-controlled content. Two shapes defeat the two checks:
- A URL that contains
m.flickr.comsomewhere in the string, which satisfies the unanchored regex without the host being m.flickr.com. - A protocol-relative URL starting with
//, which satisfies the leading-slash rule while resolving to a different host.
Why two shapes? Because the site had two separate checks, and each check had its own hole. The first shape exploits the loose regex: the text contains the trusted hostname, so the regex is satisfied, even though the actual destination is elsewhere. The second shape exploits the slash rule: the address starts with a slash, so the rule is satisfied, even though the browser will resolve it to a different host. Either one alone is enough to get past the loader's idea of safety.
Step 2: Let the loader fetch it
The victim opens the link. The loader reads the fragment, applies its two checks, both pass, and it issues an AJAX request to the attacker's server. Because the attacker's server returns CORS headers permitting the request, the browser completes it instead of blocking it.
This is the step where CORS turns a harmless-looking bug into a real one. Without CORS, the browser would have stopped the request at the door. With CORS, the attacker's server holds the door open, and the browser walks the response straight back to the page.
Step 3: Render the response as HTML
The response body, which the attacker fully controls, is written into the page with innerHTML. The markup is parsed in the context of m.flickr.com, so any script in it runs in Flickr's origin.
This is the payoff. The attacker's content is now part of the Flickr page, in Flickr's origin, with all the trust that implies. From the browser's point of view, it is Flickr's own code.
Root cause
Two validation mistakes combine with one rendering decision:
- Unanchored regex. A substring match on the raw URL string is not origin validation. The check should have compared the resolved origin exactly, not searched for the hostname inside the text.
- Leading-slash check without rejecting
//. A protocol-relative URL begins with a slash but names its own host, so the rule that was meant to keep the path local did not. innerHTMLon fetched markup. Even with a correct origin check, treating a fetched response as trusted HTML means any mistake upstream becomes script execution.
Before CORS, a cross-origin AJAX request would simply fail, so the flaw might have looked harmless. The attacker's server opts in with response headers, so the browser is willing to hand the response to the page.
A useful way to hold all three together: the first two mistakes let a foreign address through the gate, and the third mistake turns whatever comes back into live code. Any one of them alone would have been survivable. Together they form a chain.
Impact
The source post does not detail impact. The reasonable assessment is the standard one for XSS: script running in m.flickr.com's origin can act as the logged-in user, reading whatever the mobile site shows them and performing the actions that user could perform. Delivery requires only a crafted link, because the fragment carries the URL that drives the fetch.
In everyday terms, imagine someone borrowing your logged-in session for a moment. They see what you see and can click what you can click. The attacker does not need your password, because the browser already has your session and the malicious code is running inside the site that session belongs to.
Fix
Flickr fixed the issue by anchoring the regex and adding a separate check that rejects double-slash URLs, as Whitton describes. The report does not give the exact patched code.
Defence in depth, as analysis rather than a record of what Flickr shipped:
- Parse, then compare. Use the URL parser and compare the resolved origin exactly; never regex-match raw strings.
- Prefer route names over URLs. Map fragment values to an internal route table so arbitrary hosts never enter the fetch.
- Do not render fetched HTML with
innerHTML. Return data and build the DOM safely, or sanitise with a vetted library. - Add a strict Content Security Policy. Restrict
connect-srcto your own origin so the browser refuses foreign fetches even if validation regresses.
Defence in depth means layering several independent protections so that one mistake does not become a breach. Parsing a URL means letting a proper URL parser break it into its real parts, protocol, host, path, so you can compare the actual host rather than searching the raw text. Sanitising means cleaning untrusted HTML so dangerous parts are removed before it is used. A Content Security Policy (CSP) is a set of instructions a site sends to the browser saying which sources of content are allowed; connect-src is the part that controls where the page may send background requests.
A route table and a parser-based resolver, as a suggested remediation:
const ROUTES = new Set(["/photos", "/explore", "/groups", "/settings"]);
Line by line:
const ROUTES = new Set([...])creates a fixed list of allowed route names, here/photos,/explore,/groupsand/settings. ASetis a collection that can be asked "do you contain this value?" quickly. The point is that only these four names are ever acceptable, so anything else is rejected before any fetch happens.
function resolveFragment(hash) { const raw = decodeURIComponent(hash.replace(/^#/, "")); let url; try { url = new URL(raw, window.location.origin); // handles "//host" too } catch { return null; } if (url.origin !== window.location.origin) return null; // exact match const base = "/" + url.pathname.split("/")[1]; return ROUTES.has(base) ? url.pathname + url.search : null;}async function loadPage(hash) { const path = resolveFragment(hash); if (!path) return showNotFound(); const data = await fetch(path, { credentials: "same-origin" }).then(r => r.json()); renderSafely(data); // DOM APIs, no innerHTML}
Line by line:
function resolveFragment(hash) {starts a function whose job is to turn a fragment into a safe path, or return nothing if it cannot.const raw = decodeURIComponent(hash.replace(/^#/, ""));strips the leading#and decodes any percent-encoded characters, so the function works with the plain text of the fragment.let url;declares a variable to hold the parsed URL.try {begins a block that may fail, because parsing can throw an error on malformed input.url = new URL(raw, window.location.origin);uses the browser's own URL parser, resolving the fragment against the current origin. The comment notes that this handles//hosttoo, because the parser normalises protocol-relative input into a full URL with a real host.} catch {catches the error if parsing fails.return null;means "give up, this is not acceptable".if (url.origin !== window.location.origin) return null;is the exact origin comparison. If the resolved origin is not the current origin, reject. This is the check the original regex was trying to be and failing.const base = "/" + url.pathname.split("/")[1];takes the first segment of the path and rebuilds it as a route name, for example/photos.return ROUTES.has(base) ? url.pathname + url.search : null;returns the path and query string only if the route is in the allowlist, otherwisenull. So even a same-origin URL must match a known route.async function loadPage(hash) {starts the loader, markedasyncbecause it will wait for network responses.const path = resolveFragment(hash);runs the resolver.if (!path) return showNotFound();if the resolver rejected the fragment, show a not-found state and stop.const data = await fetch(path, { credentials: "same-origin" }).then(r => r.json());fetches the path with same-origin credentials and reads the response as JSON.awaitmeans wait for the result before continuing.credentials: "same-origin"means send cookies only when the request stays on the same origin.renderSafely(data);hands the data to a renderer that builds the page with DOM APIs rather thaninnerHTML, so nothing in the data is parsed as live HTML.
The resolver parses the fragment against the current origin, which normalises protocol-relative input, then rejects anything whose resolved origin differs. Surviving paths must match a known route, and the loader fetches JSON with same-origin credentials and renders it through DOM APIs rather than innerHTML.
Variants to test
If you want to look for similar bugs in other sites, these are the shapes to try. Each one is a question you can ask of a page, not a guarantee of a finding.
- Unanchored hostname checks elsewhere. Look for client-side validation that tests
url.includes(host)or an unanchored regex. A positive result is a URL whose host is not the target but whose string contains the target hostname, still being fetched. - Protocol-relative input. Try
//attacker.example/...wherever a path is expected. A positive result is a request that leaves the origin despite a leading-slash rule. - Fragment-driven fetches. Find single-page apps that read a URL from
location.hashand fetch it. A positive result is a request to a host you control, triggered purely by the fragment. - CORS-permissive attacker servers. Serve permissive CORS headers from your test server and watch whether the browser completes the cross-origin fetch. A positive result is a response body reaching the page instead of a CORS error.
innerHTMLsinks after fetch. Trace what happens to fetched markup. A positive result is attacker-controlled markup being parsed and executed in the target origin.- CSP
connect-srccoverage. Check whether a policy restricts outbound fetches to the site's own origin. A positive result is a foreign fetch succeeding where the policy should have blocked it.
A sink is the place in code where untrusted data finally gets used in a dangerous way, such as being written into the page as HTML. Finding the sink is often the moment a suspected bug becomes a real one.
Glossary
- AJAX: a way for a page to ask a server for more data in the background, without reloading the whole page.
- Anchoring (regex): pinning a pattern to a fixed position in the text, such as the start, so it cannot match just anywhere.
- API: a defined way for one piece of software to ask another for data or actions; here, the background requests the page makes to a server.
- Content Security Policy (CSP): instructions a site sends to the browser listing which sources of content and requests are allowed.
connect-src: the part of a CSP that controls where the page may send background requests.- CORS (Cross-Origin Resource Sharing): browser rules that let one website's code read data from another website, but only when the other website sends headers granting permission.
- Cross-origin: involving a different origin from the current page, where origin is protocol plus host plus port.
- CWE: a catalogue of common weakness types used to classify software flaws.
- DOM: the browser's in-memory model of the page, which JavaScript reads and changes.
- DOM-based XSS: XSS where the malicious data is handled entirely in the browser by page JavaScript, rather than being reflected by the server.
- Defence in depth: layering several independent protections so one failure does not become a breach.
- Fragment (URL fragment): the part of a web address after the
#, often used to point at a section or, in single-page apps, to carry navigation state. - Header (response header): small metadata a server sends alongside content, such as CORS permissions.
- HTML: the markup language that describes the structure of a web page.
innerHTML: a JavaScript property that sets an element's contents from a string of HTML, causing the browser to parse and run any markup in it.- JavaScript: the programming language that runs in the browser and makes pages interactive.
- JSON: a simple text format for structured data, commonly returned by APIs.
- Origin: the combination of protocol, host and port that defines a security boundary in the browser.
- Parsing (a URL): breaking a web address into its real parts, such as protocol, host and path, so they can be compared accurately.
- Protocol-relative URL: a web address starting with
//and no protocol, so the browser fills in the protocol from the current page while the address names its own host. - Regex (regular expression): a pattern used to search text for a particular shape.
- Route table: a fixed list of allowed page names that a single-page app maps fragment values to, so arbitrary addresses never enter a fetch.
- Sanitising: cleaning untrusted HTML so dangerous parts are removed before use.
- Single-page application (SPA): a site that loads one page and swaps content in and out with JavaScript instead of loading fresh pages.
- Sink: the place in code where untrusted data is finally used in a dangerous way, such as being written into the page as HTML.
- Substring: any contiguous run of characters inside a longer string.
- XSS (cross-site scripting): a flaw where an attacker gets their own code to run inside someone else's website, in a real visitor's browser.