DOM based CSS Injection on grammarly.com
The grammarly.com embedded page reads an 'extcss' query parameter and loads it as an external stylesheet without validating its origin. An attacker could supply a malicious CSS file to spoof the page for phishing, and on older browsers possibly execute JavaScript.
- Triaged in 5 hours
- Fixed in 54 days
- Paid in 20 hours
- Disclosed after 2 months
Summary: An attacker can inject an external css file which can lead to phishing attacks and xss in older browsers.
Description: Within the main.js file the following code exists:
t.prototype.componentWillMount = function () {
var e = this.getCtx().nav.waypoint.query,
t = e.extcss,
n = e.affParams,
a = e.minWords;
this.affParams = n ? JSON.parse(decodeURIComponent(n)) : {
},
this.minWords = parseInt(a, 10),
t && this.addExternalCss(t)
},
t.prototype.addExternalCss = function (e) {
var t = document.createElement('link');
t.setAttribute('href', e),
t.setAttribute('rel', 'stylesheet'),
t.setAttribute('type', 'text/css'),
document.head.appendChild(t)
},
Which allows an external css file to be loaded via the extcss parameter without any kind of origin checking or filtering.
Browsers Verified In:
Chrome Version 72.0.3626.109 Firefox 65.0.1
Steps To Reproduce:
- Visit
https://www.grammarly.com/embedded?height=300&extcss=https://www.dl.dropboxusercontent.com/s/e0g51ibqswh0v7d/xss.css?dl=0
Supporting Material/References:
- CSS Injection can be used to create a phishing page like so:

Impact
An attacker can use an external css file to spoof the page to their liking allowing for phishing attacks and if the victim is on an older browser an attacker can execute javascript as well.
Context
Grammarly's marketing site at www.grammarly.com includes an embedded view, reachable at the /embedded path, that is designed to be loaded inside an iframe or similar container. The page accepts query parameters that configure how the embedded experience behaves. Among them is extcss, which lets the page load an external stylesheet, and affParams, which carries affiliate parameters that are parsed as JSON.
The researcher found that the way this parameter is handled allows an arbitrary external CSS file to be attached to the document, with no origin checking or filtering.
Setup
The researcher verified the behaviour in two browsers:
| Browser | Version |
|---|---|
| Chrome | 72.0.3626.109 |
| Firefox | 65.0.1 |
No account, role or special tooling is described. The proof of concept uses a CSS file hosted on a public file-sharing link.
Finding it
The starting point was the site's main.js bundle. Inside it, the researcher found a component whose componentWillMount reads three values from the navigation waypoint query: extcss, affParams and minWords. The relevant code is:
t.prototype.componentWillMount = function () {
var e = this.getCtx().nav.waypoint.query,
t = e.extcss,
n = e.affParams,
a = e.minWords;
this.affParams = n ? JSON.parse(decodeURIComponent(n)) : {
},
this.minWords = parseInt(a, 10),
t && this.addExternalCss(t)
},
t.prototype.addExternalCss = function (e) {
var t = document.createElement('link');
t.setAttribute('href', e),
t.setAttribute('rel', 'stylesheet'),
t.setAttribute('type', 'text/css'),
document.head.appendChild(t)
},
Two things stand out. First, extcss is taken straight from the query string and passed to addExternalCss whenever it is present. Second, addExternalCss builds a <link> element, sets its href to that value, marks it as a stylesheet and appends it to document.head. There is no allowlist of hosts, no scheme check and no sanitisation of the URL. Any value the attacker puts in extcss becomes the href of a stylesheet the page loads.
Exploitation
Step 1: Host a malicious stylesheet
The researcher placed a CSS file on a public file-sharing host, so that the URL is reachable by any browser. The file is named xss.css in the report.
Step 2: Send the victim a crafted URL
The proof of concept is a single URL against the embedded page, with the stylesheet URL supplied in extcss:
https://www.grammarly.com/embedded?height=300&extcss=https://www.dl.dropboxusercontent.com/s/e0g51ibqswh0v7d/xss.css?dl=0
The extcss parameter carries the attacker-controlled stylesheet URL. When the page loads, componentWillMount reads extcss, calls addExternalCss, and the browser fetches and applies the remote CSS to the Grammarly page.
Step 3: Abuse the injected CSS
Once the stylesheet is applied, the attacker controls the presentation of the page. The researcher demonstrated this by turning the page into a phishing page: the injected CSS can reposition, hide or restyle elements so that the page looks the way the attacker wants.

The report includes a screenshot illustrating that CSS injection can be used to create a phishing page.
Root cause
The mistake is in the client-side code. The extcss query parameter is treated as trusted input: its value is assigned directly to the href of a newly created <link rel="stylesheet"> element and appended to the document head. Nothing validates the origin of the URL, restricts it to an expected host, or filters its contents. Because the parameter is read from the URL, anyone who can get a victim to open a crafted link controls which stylesheet the page loads.
The report does not mention a Content Security Policy or any other control that would have limited which stylesheets the page may load, so the client-side check is effectively the only barrier, and there is none.
Impact
The researcher rates the impact as follows. An attacker can load an external CSS file to spoof the page to their liking, which enables phishing attacks: the victim sees a Grammarly page whose appearance is controlled by the attacker. In addition, if the victim is on an older browser, the attacker can execute JavaScript as well. The report does not name the specific older browsers or the technique by which script execution would occur; it only states that this is possible on older browsers.
The severity recorded for the report is low, and the weakness is classified as DOM-based cross-site scripting. The bounty paid was 250.00 USD.
Fix
The change that follows from the finding is to stop trusting extcss: validate the value against an allowlist of expected origins (or remove the parameter entirely), and refuse to create the <link> element for anything else.
Variants to test
- Other parameters that end up in
hreforsrc. Grep the JavaScript bundle forsetAttribute('href',setAttribute('src',createElement('link')andcreateElement('script'). A positive result is a query parameter whose value reaches one of these calls without an origin check. - Stylesheet URLs with unusual schemes. Try values such as
data:or protocol-relative URLs in the same parameter. A positive result is the browser applying the stylesheet, which shows the check is missing or incomplete rather than merely host-based. - Embedded and iframe-oriented views. Pages built to be embedded often accept presentation parameters from the parent context. Look for
extcss-style names (css,theme,style,stylesheet) on/embedded,/widgetor similar paths. A positive result is a remote stylesheet loading from an attacker-controlled host. - CSS-based data exfiltration. Where CSS injection is confirmed, test attribute selectors combined with
background-imagerequests to see whether page content can be leaked. A positive result is an outbound request whose URL varies with the DOM content.
Hunting notes
This kind of bug tends to hide in client-side bundles rather than in server responses: the parameter is read in JavaScript, so it will not show up in a proxy history unless you actually exercise the page. The signal during recon is a marketing or embeddable page that accepts styling or layout parameters in the query string. Pulling the JavaScript bundle and searching for createElement('link'), rel, stylesheet and setAttribute('href' is a quick way to find candidates.
The researcher supported the finding with a single reproducible URL, the browser versions where it was verified, and a screenshot showing a phishing page CSS injection can create. That combination, a working link and a visible result, is what makes a low-severity CSS injection credible to a program.
What happened, in plain words
Grammarly runs a marketing website at www.grammarly.com. Part of that site is a special page at the path /embedded, built to be shown inside another page, for example inside a frame (an iframe) on a partner's site. Think of it like a shop window that a partner can place inside their own shop: the window shows Grammarly content, but the partner decides where it sits.
To make that possible, the embedded page accepts settings in its web address, in the part after the question mark. Those settings are called query parameters. A query parameter is a name and a value joined by =, and several of them are joined by &. For example, ?height=300 tells the page how tall to be. It is the same idea as filling in a form before you press send: the page reads the answers from the address bar.
One of those settings is called extcss. A stylesheet (CSS, short for Cascading Style Sheets) is a file that tells a browser how things should look: colours, sizes, positions, what is visible and what is hidden. It does not contain logic or instructions, only appearance rules.
The researcher found that the page takes whatever address you put in extcss and loads it as a stylesheet, without checking where it comes from. That means an attacker can supply their own stylesheet, and the victim's browser will apply it to the Grammarly page. The attacker then controls how the page looks. They can restyle the page to their liking, which enables phishing attacks. That is called phishing. On older browsers, the report says the same trick can go further and run JavaScript, which is code that actually executes in the page.
The report classifies this as DOM-based cross-site scripting. The DOM (Document Object Model) is the browser's live model of the page: every element on screen is an object in that model, and JavaScript can add, remove or change them. DOM-based means the problem lives in the page's own JavaScript, running in the browser, rather than in the server's reply. Cross-site scripting (XSS) is the general name for getting your own content or code into someone else's page. Here the injected content is a stylesheet rather than a script, which is why the impact is mostly visual, but the report still files it under the XSS family.
Setup
The researcher checked the behaviour in two browsers:
| Browser | Version |
|---|---|
| Chrome | 72.0.3626.109 |
| Firefox | 65.0.1 |
No account, role or special tooling is described. The only thing the attacker needs is somewhere to host a CSS file that the victim's browser can reach. In the report that place is a public file-sharing link.
Finding it
The starting point was the site's main.js bundle. A JavaScript bundle is one large file containing the site's client-side code, the code that runs in your browser after the page arrives. It is public: your browser downloads it to run the page, so anyone can read it. Reading it is like reading the recipe of a dish you were served.
Inside that bundle the researcher found a component. In modern web code, a component is a self-contained piece of the page with its own behaviour and lifecycle. This one has a function called componentWillMount, which runs before the component is first rendered. That timing matters: whatever it does happens automatically as the page loads, with no click required.
The relevant code is:
t.prototype.componentWillMount = function () {
var e = this.getCtx().nav.waypoint.query,
t = e.extcss,
n = e.affParams,
a = e.minWords;
this.affParams = n ? JSON.parse(decodeURIComponent(n)) : {
},
this.minWords = parseInt(a, 10),
t && this.addExternalCss(t)
},
t.prototype.addExternalCss = function (e) {
var t = document.createElement('link');
t.setAttribute('href', e),
t.setAttribute('rel', 'stylesheet'),
t.setAttribute('type', 'text/css'),
document.head.appendChild(t)
},
Line by line, in plain words:
t.prototype.componentWillMount = function () {starts the function that runs before the component appears.var e = this.getCtx().nav.waypoint.query,fetches the query object, the collection of settings from the address bar, and stores it ine.t = e.extcss,reads theextcsssetting intot.n = e.affParams,reads theaffParamssetting inton.a = e.minWords;reads theminWordssetting intoa.this.affParams = n ? JSON.parse(decodeURIComponent(n)) : {takesaffParams, decodes it (turns%20-style escapes back into normal characters) and parses it as JSON, a text format for structured data. If the setting is missing, it uses an empty object{}.this.minWords = parseInt(a, 10),turnsminWordsinto a whole number.t && this.addExternalCss(t)is the important line: ifextcsshas a value, calladdExternalCsswith it.t.prototype.addExternalCss = function (e) {starts the helper that takes a URL ase.var t = document.createElement('link');creates a new<link>element. A<link>element is how a page tells the browser to fetch an external file, such as a stylesheet.t.setAttribute('href', e),sets the element'shref(its target address) to the value passed in, with no check on it.t.setAttribute('rel', 'stylesheet'),marks the link as a stylesheet, so the browser knows to treat the file as styling rules.t.setAttribute('type', 'text/css'),declares the file type as CSS.document.head.appendChild(t)inserts the element into the page's head, the part of the document where the browser looks for stylesheets and other resources. Once it is there, the browser fetches and applies the file.
Two things stand out. First, extcss is taken straight from the address bar and passed to addExternalCss whenever it is present. Second, addExternalCss builds a <link> element, sets its href to that value, marks it as a stylesheet and appends it to document.head. There is no allowlist of hosts (a list of addresses that are permitted), no scheme check (a check that the address starts with https:// and not something else) and no cleaning of the URL. Any value the attacker puts in extcss becomes the href of a stylesheet the page loads.
Exploitation
Step 1: Host a malicious stylesheet
The researcher placed a CSS file on a public file-sharing host, so that the URL is reachable by any browser. The file is named xss.css in the report.
Step 2: Send the victim a crafted URL
The proof of concept is a single URL against the embedded page, with the stylesheet URL supplied in extcss:
https://www.grammarly.com/embedded?height=300&extcss=https://www.dl.dropboxusercontent.com/s/e0g51ibqswh0v7d/xss.css?dl=0
Breaking it down:
https://www.grammarly.com/embeddedis the real Grammarly embedded page. The victim is on Grammarly's own site, which is why the trick is convincing.?height=300is the first query parameter.&extcss=starts the second parameter, the one the attacker controls.https://www.dl.dropboxusercontent.com/s/e0g51ibqswh0v7d/xss.css?dl=0is the attacker's stylesheet, hosted on a public file-sharing service.
When the page loads, componentWillMount reads extcss, calls addExternalCss, and the browser fetches and applies the remote CSS to the Grammarly page. The victim does not have to click anything on the page: opening the link is enough.
Step 3: Abuse the injected CSS
Once the stylesheet is applied, the attacker controls the presentation of the page. The researcher demonstrated this by turning the page into a phishing page: the injected CSS can reposition, hide or restyle elements so that the page looks the way the attacker wants. A phishing page is a fake page that imitates a real one to trick someone into typing a password or payment details.

The report includes a screenshot illustrating that CSS injection can be used to create a phishing page.
Root cause
The mistake is in the client-side code. The extcss query parameter is treated as trusted input: its value is assigned directly to the href of a newly created <link rel="stylesheet"> element and appended to the document head. Nothing validates the origin of the URL, restricts it to an expected host, or filters its contents. Because the parameter is read from the URL, anyone who can get a victim to open a crafted link controls which stylesheet the page loads.
The report does not mention a Content Security Policy or any other control that would have limited which stylesheets the page may load. A Content Security Policy (CSP) is a rule set the server sends with the page that tells the browser which sources it may load files from. Without one, the client-side check is effectively the only barrier, and there is none.
Impact
The researcher rates the impact as follows. An attacker can load an external CSS file to spoof the page to their liking, which enables phishing attacks: the victim sees a Grammarly page whose appearance is controlled by the attacker. In addition, if the victim is on an older browser, the attacker can execute JavaScript as well. The report does not name the specific older browsers or the technique by which script execution would occur; it only states that this is possible on older browsers.
The severity recorded for the report is low, and the weakness is classified as DOM-based cross-site scripting. The bounty paid was 250.00 USD.
Fix
The change that follows from the finding is to stop trusting extcss: validate the value against an allowlist of expected origins (or remove the parameter entirely), and refuse to create the <link> element for anything else.
Variants to test
- Other parameters that end up in
hreforsrc. Grep the JavaScript bundle forsetAttribute('href',setAttribute('src',createElement('link')andcreateElement('script'). Grep is a command-line search tool that finds text inside files. A positive result is a query parameter whose value reaches one of these calls without an origin check. - Stylesheet URLs with unusual schemes. Try values such as
data:or protocol-relative URLs in the same parameter. Adata:URL carries the file's contents inside the address itself instead of pointing to a server, and a protocol-relative URL starts with//and borrows the current page's scheme. A positive result is the browser applying the stylesheet, which shows the check is missing or incomplete rather than merely host-based. - Embedded and iframe-oriented views. Pages built to be embedded often accept presentation parameters from the parent context. Look for
extcss-style names (css,theme,style,stylesheet) on/embedded,/widgetor similar paths. A positive result is a remote stylesheet loading from an attacker-controlled host. - CSS-based data exfiltration. Where CSS injection is confirmed, test attribute selectors combined with
background-imagerequests to see whether page content can be leaked. An attribute selector is a CSS rule that matches an element by one of its attributes, andbackground-imagemakes the browser fetch a picture. A positive result is an outbound request whose URL varies with the DOM content.
Hunting notes
This kind of bug tends to hide in client-side bundles rather than in server responses: the parameter is read in JavaScript, so it will not show up in a proxy history unless you actually exercise the page. A proxy is a tool that sits between your browser and the site and records every request and response. The signal during recon is a marketing or embeddable page that accepts styling or layout parameters in the query string. Recon means the early information-gathering phase of a test. Pulling the JavaScript bundle and searching for createElement('link'), rel, stylesheet and setAttribute('href' is a quick way to find candidates.
The researcher supported the finding with a single reproducible URL, the browser versions where it was verified, and a screenshot showing a phishing page CSS injection can create. That combination, a working link and a visible result, is what makes a low-severity CSS injection credible to a program.
Glossary
- API: a defined way for one piece of software to ask another for data or actions, like a menu of requests a kitchen will accept.
- Allowlist: a list of things that are explicitly permitted; anything not on the list is refused.
- Attribute selector: a CSS rule that matches an element based on one of its attributes, such as its value or name.
- Bounty: money a company pays a researcher for reporting a valid security bug.
- Browser: the program you use to open websites, such as Chrome or Firefox.
- Bundle: one large JavaScript file containing a site's client-side code, downloaded by the browser.
- Component: a self-contained piece of a web page with its own behaviour and lifecycle.
- Content Security Policy (CSP): rules sent with a page that tell the browser which sources it may load files from.
- CSS (Cascading Style Sheets): a file of rules describing how a page should look.
- CSS injection: getting your own CSS rules applied to someone else's page.
data:URL: an address that carries a file's contents inside the address itself instead of pointing to a server.- DOM (Document Object Model): the browser's live model of the page, which JavaScript can read and change.
- DOM-based: a problem that lives in the page's own JavaScript running in the browser, not in the server's reply.
- Exfiltration: getting data out of a page or system to a place the attacker controls.
- Grep: a command-line tool that searches for text inside files.
href: the attribute of a link element that holds its target address.- HTML element: a building block of a page, such as a link, image or heading.
- iframe: a frame that shows one page inside another page.
- JavaScript: the programming language that runs in the browser and makes pages interactive.
- JSON: a text format for structured data, made of names and values.
<link>element: the HTML element a page uses to tell the browser to fetch an external file such as a stylesheet.- Origin: the combination of scheme, host and port that identifies where a resource comes from.
- Parameter (query parameter): a name and value in the part of a URL after the question mark, used to pass settings to a page.
- Phishing: a fake page or message that imitates a real one to trick someone into giving away credentials or money.
- Protocol-relative URL: an address starting with
//that borrows the current page's scheme. - Proxy: a tool that sits between your browser and a site and records the requests and responses.
- Recon: the early information-gathering phase of a security test.
- Scheme: the first part of a URL, such as
https, that says how to fetch the resource. - Severity: a rating of how serious a bug is, often low, medium, high or critical.
- Stylesheet: a file of CSS rules that a page loads to control its appearance.
- XSS (cross-site scripting): getting your own content or code into someone else's page.