Skip to content
XSS Write-up Intermediate

$6000 with Microsoft Hall of Fame | Microsoft Firewall Bypass | CRLF to XSS | Microsoft Bug Bounty

A Microsoft subdomain was vulnerable to CRLF injection, allowing an attacker to inject arbitrary headers and, by chaining, achieve XSS. The attacker could set cookies, redirect users, and execute JavaScript in the victim's browser.

Neh Patel Follow

Published on infosecwriteups.com

Bounty$6,000 View original

Hello Hackers, Hope you are doing great. I am Neh Patel also known as THECYBERNEH, I am a Security Researcher from India.

Neh Patel, on infosecwriteups.com

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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Context

This is a write-up of a CRLF injection that was chained into XSS on a Microsoft subdomain, found by Neh Patel (@thecyberneh). The subdomain is not named in the report; it is described only as one that carries features for premium customers. The researcher's reasoning was that paid features are less explored by other security teams, so the subdomain was worth a closer look. The bug was rated P2, severity Important, and paid a total of $6000 across two reports, together with a Microsoft Hall of Fame entry.

The report describes CRLF injection, where a server passes CR and LF through unencoded into response headers. CRLF injection is the class of bug where the server passes the special characters CR (Carriage Return) and LF (Line Feed) through unencoded into headers such as Location or Set-Cookie. Because CRLF marks the end of a line in HTTP, anything an attacker places after it can become a new response header, and a blank line ends the header block entirely, letting the attacker write into the response body.

Setup

No accounts, roles, tool versions or special tooling are described. The work was manual: the researcher tested subdomains by hand, going through 50 to 70 of them and checking the functionality on each. The only precondition that matters is that the target reflects a path segment into a response header without encoding CR and LF.

Finding it

After two or three weeks on Microsoft with only P4 and P5 results, the researcher settled on the premium-feature subdomain and tested the free features first without success. The next phase was non-functional and server-side testing, starting with Host Header Injection and then moving to CRLF injection, described as the most ignored vulnerability.

The first payload was placed directly in the URL path:

Text
/%0D%0A%20Set-Cookie:whoami=thecybernehso main URL :-  https://subDomain.microsoft.com/%0D%0A%20Set-Cookie:whoami=thecyberneh

No injection occurred. The server answered with 400 Bad Request and the HTML body "HTTP Error 400. The requested URL is invalid."

That response is what made the target interesting. The researcher's expectation was that a well-protected server treats the payload as an ordinary path segment and, finding no such path, returns 404 Not Found. A 400 instead of the expected 404 suggested to the researcher that the server was not well protected or the firewall was weak.

To confirm, a random path was requested:

Text
https://subDomain.microsoft.com/abcxyzabcxyz

This returned 404 Not Found with the body "We are sorry, the page you requested cannot be found. The URL may be misspelled or the page you're looking for is no longer available". The contrast was the signal: a missing path gives 404, while the CRLF payload gives 400, so the payload was reaching a parser that reacted to it.

Exploitation

Step 1: basic payloads are blocked

Several variations were tried in one go:

Text
%0D%0A%20Set-Cookie:whoami=thecyberneh%20%0D%0ASet-Cookie:whoami=thecyberneh%0A%20Set-Cookie:whoami=thecyberneh%2F%2E%2E%0D%0ASet-Cookie:whoami=thecyberneh

Every one still produced 400 Bad Request. The conclusion was that the firewall blocks normal, basic payloads and that a different encoding was needed.

Step 2: GBK encoding as a firewall bypass

Research turned up GBK encoding, in which the CRLF characters can be represented as multi-byte characters:

Text
Payload responsible for CRLF injection is :- 嘍嘊

Because those characters would otherwise cause errors in transit, they were URL encoded:

Text
BeforeURL EncodingMain Payload:- 嘍嘊After URL Encoding嘍 :- %E5%98%8D嘊 :- %E5%98%8A

So 嘍 becomes %E5%98%8D and 嘊 becomes %E5%98%8A. The new URL was:

Text
https://subDomain.microsoft.com/%E5%98%8D%E5%98%8ASet-Cookie:crlfinjection=thecyberneh

This time the response contained the header Set-Cookie: crlfinjection=thecyberneh, confirming the injection.

From the original on infosecwriteups.com

The screenshot shows the response with the injected Set-Cookie header. Rather than report at this point, the researcher kept going to chain the primitive into something more impactful.

Step 3: forcing a blank line to reach the body

HTTP requests and responses end their header block with a blank line, as the report illustrates with line 13 in the request and line 20 in the response.

From the original on infosecwriteups.com

The image shows the request and response headers with the terminating blank line marked. By default the server was sending a normal response:

From the original on infosecwriteups.com

These two images show the structure of the default response and the real captured response.

For XSS the JavaScript has to land in the body, because that is where browsers render and execute it. That means the server must be made to emit a blank line after the attacker's headers, so that everything following is treated as body:

From the original on infosecwriteups.com

The diagram shows the desired response shape: the attacker's headers, then a blank line, then the XSS payload in the body.

A single CRLF payload, 嘍嘊 URL encoded as %E5%98%8D%E5%98%8A, did not produce the blank line. Inserting the payload twice did: the server then sent a single blank line in the response.

From the original on infosecwriteups.com

These images show the intended response structure and the real response with the blank line in place.

Step 4: the XSS payload and its encoding

The payload was built to inject a script tag into the body. The angle brackets were encoded the same way as the CRLF characters:

Text
“<” as 嘼“>” as 嘾
From the original on infosecwriteups.com

These images show the payload construction and the encoded form used to bypass the firewall.

The final payload, with URL encoding applied throughout, was:

Text
#ENCODING“<” --> 嘼 --> %E5%98%BC“>” --> 嘾 --> %E5%98%BEhttps://subDomain.microsoft.com/%E5%98%8D%E5%98%8ASet-Cookie=whoami=thecyberneh%E5%98%8D%E5%98%8A%E5%98%8D%E5%98%8A%E5%98%8D%E5%98%8A%E5%98%BCscript%E5%98%BEalert(1);%E5%98%BC/script%E5%98%BE

Read from left to right, the URL contains: a CRLF pair followed by a Set-Cookie header, then three more CRLF pairs to produce the blank line that ends the header block, then %E5%98%BCscript%E5%98%BEalert(1);%E5%98%BC/script%E5%98%BE, which decodes to a script tag calling alert(1).

From the original on infosecwriteups.com

The screenshots show the resulting execution.

Step 5: automation and a second finding

After submitting the bug, the researcher wrote a shell script that checks CRLF on a list of subdomains. Running it against Microsoft's subdomains found another CRLF on a different domain. Both were reported, and a bounty response arrived within three weeks.

Root cause

The server takes a value from the URL path and writes it into a response header without encoding CR and LF. Because the CRLF characters survive into the header block, the attacker controls where headers end and the body begins. The plain %0D%0A payloads returned 400, while the GBK-encoded form produced an injected Set-Cookie header. The report does not describe the server-side code, so the exact decoding step that turns the GBK bytes into CRLF is not shown.

Impact

The report lists the following consequences:

  • Arbitrary header injection
  • Arbitrary cookie injection
  • JavaScript injection (XSS)
  • HTML injection
  • HTTP request splitting
  • Bypassing cookie-based CSRF protection
  • Application denial of service using overly long cookies
  • The attacker can set new headers

These apply where the injected value reaches a response the victim's browser renders, which is the case demonstrated here. The researcher notes that further exploitation of the CRLF was left out of the write-up because it was already long and because chaining it with other impactful bugs is straightforward.

Fix

The report does not say what Microsoft changed. A reasonable mitigation would be to encode or reject CR and LF in values written into response headers.

Variants to test

  1. Send a plain CRLF payload in a path segment and compare the status code with a random path. A 400 where a random path gives 404 suggests the input reaches a parser that reacts to CRLF.
  2. Replace %0D%0A with the GBK-encoded form %E5%98%8D%E5%98%8A and watch for an injected Set-Cookie header in the response.
  3. Repeat the CRLF pair several times to try to force a blank line, then place a script tag after it. A positive result is the script executing in the browser.
  4. Encode the angle brackets as %E5%98%BC and %E5%98%BE when the firewall blocks literal < and >.
  5. Run the same checks across a list of subdomains with a script; the researcher's script found another CRLF on a different Microsoft domain.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 13 min read.

What happened, in plain words

A security researcher, Neh Patel (known online as @thecyberneh), found a bug on a Microsoft website. The bug let him slip extra instructions into the website's reply. He used it to make the browser run a small piece of JavaScript code that he chose. That kind of bug is called cross-site scripting, or XSS for short. Microsoft rated it P2, which is a high priority, with severity Important, and paid a total of $6000 across two reports. He also got a place in the Microsoft Hall of Fame, a public list of researchers who have reported valid bugs.

The website is not named in the report. It is described only as a subdomain that carries features for premium (paying) customers. The researcher's reasoning was simple: features that cost money are used by fewer people, so other security teams are less likely to have tested them. That made the subdomain worth a closer look.

The bug class is CRLF injection. CR and LF are two invisible characters that mark the end of a line in HTTP, the language browsers and web servers use to talk to each other. If a server copies text from a visitor's request into its reply without cleaning it, and that text contains CR and LF, the server can be tricked into treating part of the visitor's text as a brand new line in its reply. That new line can be a new header (a label at the top of the reply) or, if the attacker adds a blank line, the start of the body (the part the browser displays). The researcher used this to inject a cookie header, then to force a blank line, and finally to put a script tag into the body so the browser would run it.

Setup

The report does not describe any accounts, roles, tool versions or special tooling. The work was manual. The researcher tested subdomains by hand, going through 50 to 70 of them and checking the functionality on each. The only precondition that matters is that the target copies a piece of the URL path into a response header without encoding CR and LF.

Finding it

After two or three weeks on Microsoft with only P4 and P5 results (lower-priority findings), the researcher settled on the premium-feature subdomain. He tested the free features first and found nothing. The next phase was non-functional and server-side testing. Non-functional testing means looking at how the server behaves rather than what a feature does: for example, how it reacts to strange input. He started with Host Header Injection, a bug where the server trusts the Host header (the part of a request that says which website the visitor wants) and uses it in links or redirects. Then he moved to CRLF injection, which he calls the most ignored vulnerability.

The first payload was placed directly in the URL path:

Text
/%0D%0A%20Set-Cookie:whoami=thecybernehso main URL :-  https://subDomain.microsoft.com/%0D%0A%20Set-Cookie:whoami=thecyberneh

Line by line:

  • /%0D%0A%20Set-Cookie:whoami=thecyberneh is the path part of the URL. %0D is the URL-encoded form of CR (carriage return), %0A is the URL-encoded form of LF (line feed), and %20 is a space. So the path contains a CRLF pair, a space, and then the text Set-Cookie:whoami=thecyberneh.
  • so main URL :- is the researcher's own note, not part of the payload.
  • https://subDomain.microsoft.com/%0D%0A%20Set-Cookie:whoami=thecyberneh is the full URL he requested. subDomain.microsoft.com stands in for the real Microsoft subdomain, which the report does not name.

No injection occurred. The server answered with 400 Bad Request and the HTML body "HTTP Error 400. The requested URL is invalid." A 400 status means the server thinks the request itself is malformed.

That response is what made the target interesting. The researcher's expectation was that a well-protected server treats the payload as an ordinary path segment (a folder or file name in the URL) and, finding no such path, returns 404 Not Found. A 404 means the server understood the request but has nothing at that address. A 400 instead suggested the server was parsing the CRLF characters rather than rejecting them as a path, so the protection was weak or the firewall was not handling the input properly. A firewall here is a filter that sits in front of the website and blocks requests that look malicious.

To confirm, a random path was requested:

Text
https://subDomain.microsoft.com/abcxyzabcxyz

Line by line:

  • https://subDomain.microsoft.com/ is the site address.
  • abcxyzabcxyz is a made-up path that almost certainly does not exist.

This returned 404 Not Found with the body "We are sorry, the page you requested cannot be found. The URL may be misspelled or the page you're looking for is no longer available". The contrast was the signal: a missing path gives 404, while the CRLF payload gives 400, so the payload was reaching a parser that reacted to it. A parser is the part of the server that reads and interprets the request.

Exploitation

Step 1: basic payloads are blocked

Several variations were tried in one go:

Text
%0D%0A%20Set-Cookie:whoami=thecyberneh%20%0D%0ASet-Cookie:whoami=thecyberneh%0A%20Set-Cookie:whoami=thecyberneh%2F%2E%2E%0D%0ASet-Cookie:whoami=thecyberneh

Line by line:

  • %0D%0A%20Set-Cookie:whoami=thecyberneh is the same CRLF plus space plus Set-Cookie header as before.
  • %20 is a space.
  • %0D%0ASet-Cookie:whoami=thecyberneh is another CRLF pair followed by the same header, this time without the space.
  • %0A%20Set-Cookie:whoami=thecyberneh uses only LF (no CR) followed by a space and the header.
  • %2F%2E%2E is URL-encoded /. (a slash and two dots), a common trick to confuse path handling.
  • %0D%0ASet-Cookie:whoami=thecyberneh repeats the CRLF pair and header once more.

Every one still produced 400 Bad Request. The conclusion was that the firewall blocks normal, basic payloads and that a different encoding was needed. Encoding means writing characters in a different form, for example %0D instead of an invisible CR.

Step 2: GBK encoding as a firewall bypass

Research turned up GBK encoding. GBK is a character set used for Chinese text. In it, some characters are represented by two bytes, and those bytes can happen to be the same values as CR and LF. The plain %0D%0A payloads returned 400, while the GBK-encoded form produced an injected Set-Cookie header.

Text
Payload responsible for CRLF injection is :- 嘍嘊

Line by line:

  • Payload responsible for CRLF injection is :- is the researcher's label.
  • 嘍嘊 are two Chinese characters. In GBK, their byte values correspond to CR and LF.

Because those characters would otherwise cause errors in transit, they were URL encoded:

Text
BeforeURL EncodingMain Payload:- 嘍嘊After URL Encoding嘍 :- %E5%98%8D嘊 :- %E5%98%8A

Line by line:

  • BeforeURL EncodingMain Payload:- 嘍嘊 says that before URL encoding, the main payload is the two characters 嘍嘊.
  • After URL Encoding嘍 :- %E5%98%8D says that after URL encoding, 嘍 becomes %E5%98%8D.
  • 嘊 :- %E5%98%8A says that 嘊 becomes %E5%98%8A.

So 嘍 becomes %E5%98%8D and 嘊 becomes %E5%98%8A. The new URL was:

Text
https://subDomain.microsoft.com/%E5%98%8D%E5%98%8ASet-Cookie:crlfinjection=thecyberneh

Line by line:

  • %E5%98%8D%E5%98%8A is the URL-encoded GBK form of CRLF.
  • Set-Cookie:crlfinjection=thecyberneh is the header the researcher wants the server to add to its reply. Set-Cookie tells the browser to store a small piece of data called a cookie. Here the cookie is named crlfinjection with the value thecyberneh.

This time the response contained the header Set-Cookie: crlfinjection=thecyberneh, confirming the injection. A cookie is a small label that a website asks the browser to keep and send back on later requests, often used to remember who is logged in.

From the original on infosecwriteups.com

The screenshot shows the response with the injected Set-Cookie header. Rather than report at this point, the researcher kept going to chain the primitive into something more impactful. A primitive here means a small building block that can be combined with other tricks.

Step 3: forcing a blank line to reach the body

HTTP requests and responses end their header block with a blank line, as the report illustrates with line 13 in the request and line 20 in the response.

From the original on infosecwriteups.com

The image shows the request and response headers with the terminating blank line marked. By default the server was sending a normal response:

From the original on infosecwriteups.com

These two images show the structure of the default response and the real captured response.

For XSS the JavaScript has to land in the body, because that is where browsers render and execute it. The body is the part of the reply that the browser displays as a page. That means the server must be made to emit a blank line after the attacker's headers, so that everything following is treated as body:

From the original on infosecwriteups.com

The diagram shows the desired response shape: the attacker's headers, then a blank line, then the XSS payload in the body.

A single CRLF payload, 嘍嘊 URL encoded as %E5%98%8D%E5%98%8A, did not produce the blank line. Inserting the payload twice did: the server then sent a single blank line in the response.

From the original on infosecwriteups.com

These images show the intended response structure and the real response with the blank line in place.

Step 4: the XSS payload and its encoding

The payload was built to inject a script tag into the body. A script tag is HTML that tells the browser to run JavaScript. The angle brackets were encoded the same way as the CRLF characters:

Text
“<” as 嘼“>” as 嘾

Line by line:

  • “<” as 嘼 says the less-than sign < is represented by the character 嘼.
  • “>” as 嘾 says the greater-than sign > is represented by the character 嘾.
From the original on infosecwriteups.com

These images show the payload construction and the encoded form used to bypass the firewall.

The final payload, with URL encoding applied throughout, was:

Text
#ENCODING“<” --> 嘼 --> %E5%98%BC“>” --> 嘾 --> %E5%98%BEhttps://subDomain.microsoft.com/%E5%98%8D%E5%98%8ASet-Cookie=whoami=thecyberneh%E5%98%8D%E5%98%8A%E5%98%8D%E5%98%8A%E5%98%8D%E5%98%8A%E5%98%BCscript%E5%98%BEalert(1);%E5%98%BC/script%E5%98%BE

Line by line:

  • #ENCODING is a label.
  • “<” --> 嘼 --> %E5%98%BC says < becomes 嘼, which URL-encodes to %E5%98%BC.
  • “>” --> 嘾 --> %E5%98%BE says > becomes 嘾, which URL-encodes to %E5%98%BE.
  • %E5%98%8D%E5%98%8A is the first CRLF pair.
  • Set-Cookie=whoami=thecyberneh is the injected header. Note the = instead of : after Set-Cookie; that is how it appears in the report.
  • %E5%98%8D%E5%98%8A%E5%98%8D%E5%98%8A%E5%98%8D%E5%98%8A is three more CRLF pairs, which together force the blank line that ends the header block.
  • %E5%98%BCscript%E5%98%BE decodes to <script>.
  • alert(1); is the JavaScript that will run. alert(1) makes the browser show a pop-up with the number 1.
  • %E5%98%BC/script%E5%98%BE decodes to </script>, which closes the script tag.

Read from left to right, the URL contains: a CRLF pair followed by a Set-Cookie header, then three more CRLF pairs to produce the blank line that ends the header block, then %E5%98%BCscript%E5%98%BEalert(1);%E5%98%BC/script%E5%98%BE, which decodes to a script tag calling alert(1).

From the original on infosecwriteups.com

The screenshots show the resulting execution.

Step 5: automation and a second finding

After submitting the bug, the researcher wrote a shell script that checks CRLF on a list of subdomains. A shell script is a small program that runs commands on a computer. Running it against Microsoft's subdomains found another CRLF on a different domain. Both were reported, and a bounty response arrived within three weeks.

Root cause

The server takes a value from the URL path and writes it into a response header without encoding CR and LF. Because the CRLF characters survive into the header block, the attacker controls where headers end and the body begins. The firewall in front of the application blocked the plain %0D%0A form but not the GBK-encoded form, so the encoded characters reached the application and were interpreted as line breaks.

Impact

The report lists the following consequences:

  • Arbitrary header injection: the attacker can add any header they like to the reply.
  • Arbitrary cookie injection: the attacker can set cookies in the victim's browser.
  • JavaScript injection (XSS): the attacker can run JavaScript in the victim's browser.
  • HTML injection: the attacker can add HTML to the page.
  • HTTP request splitting: the attacker can make the server treat one request as two.
  • Bypassing cookie-based CSRF protection: CSRF (cross-site request forgery) is a trick where another site makes the victim's browser send a request the victim did not intend. Some sites protect against it with a cookie; injecting cookies can get around that.
  • Application denial of service using overly long cookies: the attacker can send cookies so large that the application stops working.
  • The attacker can set new headers.

These apply where the injected value reaches a response the victim's browser renders, which is the case demonstrated here. The researcher notes that further exploitation of the CRLF was left out of the write-up because it was already long and because chaining it with other impactful bugs is straightforward.

Fix

A reasonable mitigation would be to encode or reject CR and LF in values written into response headers.

Variants to test

  1. Send a plain CRLF payload in a path segment and compare the status code with a random path. A 400 where a random path gives 404 suggests the input reaches a parser that reacts to CRLF.
  2. Replace %0D%0A with the GBK-encoded form %E5%98%8D%E5%98%8A and watch for an injected Set-Cookie header in the response.
  3. Repeat the CRLF pair several times to try to force a blank line, then place a script tag after it. A positive result is the script executing in the browser.
  4. Encode the angle brackets as %E5%98%BC and %E5%98%BE when the firewall blocks literal < and >.
  5. Run the same checks across a list of subdomains with a script; the researcher's script found another CRLF on a different Microsoft domain.

Glossary

  • API: a way for one piece of software to ask another piece of software to do something, like a waiter taking an order to the kitchen.
  • Body: the part of an HTTP request or response that carries the actual content, such as the HTML of a page.
  • Cookie: a small piece of data a website asks the browser to store and send back on later requests, often used to remember who is logged in.
  • CRLF: two invisible characters, carriage return (CR) and line feed (LF), that mark the end of a line in HTTP.
  • CRLF injection: a bug where a server copies CR and LF from user input into its reply without cleaning them, letting the attacker add new lines.
  • CSRF: cross-site request forgery, a trick where another site makes the victim's browser send a request the victim did not intend.
  • Firewall: a filter that sits in front of a website and blocks requests that look malicious.
  • GBK: a character set used for Chinese text, in which some characters are represented by two bytes that can match CR and LF.
  • Header: a label at the top of an HTTP request or response that carries information about the message, such as Set-Cookie.
  • Host Header Injection: a bug where the server trusts the Host header and uses it in links or redirects.
  • HTML: the language used to describe the structure of a web page.
  • HTTP: the language browsers and web servers use to talk to each other.
  • JavaScript: the programming language that runs in the browser and makes pages interactive.
  • Non-functional testing: testing how a system behaves rather than what a feature does, for example how it reacts to strange input.
  • Parser: the part of a server that reads and interprets a request.
  • Payload: the piece of input an attacker sends to trigger a bug.
  • P2: a priority level in bug bounties, higher than P3 and lower than P1.
  • P4 / P5: lower priority levels in bug bounties.
  • Primitive: a small building block that can be combined with other tricks.
  • Script tag: HTML that tells the browser to run JavaScript.
  • Set-Cookie: a response header that tells the browser to store a cookie.
  • Shell script: a small program that runs commands on a computer.
  • Subdomain: a part of a larger website address, such as subDomain.microsoft.com under microsoft.com.
  • URL encoding: writing characters in a different form, for example %0D instead of an invisible CR.
  • XSS: cross-site scripting, a bug that lets an attacker run JavaScript in a victim's browser.

More by Neh Patel

View all

1 more disclosed report, best first.

More from Microsoft

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.