Synthetics Recorder: Code injection when recording website with malicious content
The Synthetics Recorder's code generator escapes single quotes but places a user-controlled URL inside a multi-line comment, so a crafted URL can break out of the comment and inject JavaScript. When the recorded session is exported and run with the Synthetics runner, the injected code executes arbitrary commands on the machine.
- Triaged in 4 days
- Fixed in 7 days
- Paid in 11 days
- Disclosed after 9 months
Summary
Hello team! Synthetics recorder has a quote function to escape user-controlled input, but in one particular scenario the escaping isn't enough and a malicious website can inject arbitrary code in the recorder session.
Description
The waitForNavigation event calls quote within the context of a multi-line comment (/* ... */) so we can break out of that without using the escaped characters (reference)
In a normal situation the code generated looks like this for a navigation event to https://example.com
page.waitForNavigation(/*{ url: 'https://example.com' }*/),
but it's possible to escape out of the comment without using single quotes (which would be escaped) with a specially crafted URL like https://example.com?q=*/require(child_process).exec(touch$IFS/tmp/haxx)/*
page.waitForNavigation(/*{ url: 'https://example.com?q=*/require(`child_process`).exec(`touch$IFS/tmp/dee-see`)/*' }*/),
The syntax highlighting here on HackerOne helps visualizing how that works. $IFS is used because spaces get encoded to %20.
It's possible to have code execution when the victim uses the test feature inside of the synthetic recorder but the code we're allowed to use is fairly limited because the require function isn't available. The maximum impact is when the user saves the recorded session as a project and executes it using the synthetic runner.
Steps To Reproduce
Preparation
Install the synthetics recorder (See https://github.com/elastic/synthetics-recorder/, I'm following the instructions to run it in development mode (nvm install; nvm use; npm install; npm run dev) but you could also download the binary on the releases page)
Reproduction
-
Start Synthetics Recorder and enter
http://deesee.xyz:4567in the text box where it says "Enter a Starting URL" -
Click "Start Recording"
-
A browser has opened, this website is a modified clone of my blog. Click the GitLab icon in the top right

gl.png From the original on HackerOne -
Close the browser window
In a normal Synthetics Recorder session there would be much more steps to record but here we only did what's necessary to trigger the issue.
-
Click the "Export" button and you'll see this code
JavaScript step('Go to http://deesee.xyz:4567/', async () => { await page.goto('http://deesee.xyz:4567/'); await Promise.all([ page.waitForNavigation(/*{ url: 'https://gitlab.com/dee-see?query=*/require(`child_process`).exec(`touch$IFS/tmp/dee-see`)/*' }*/), page.click('[aria-label="GitLab"] svg') ]); });We can see the payload is in place. It's fairly obvious because we only recorded one step, but in a long recording session it would be buried deeper.
-
Click the "Export" button and save the file in a directory
-
In that directory run
npm init -y; npm install @elastic/synthetics; npx @elastic/synthetics . -
When the tests finished running observe that the
touch /tmp/dee-seecommand ran
Those last steps seem contrived, but that's how a synthetics test suite is setup and how a developer would make sure the session they just recorded would be integrated into their builds and whatnot.
Supporting Material/References:
CVSS
Confidentiality and Integrity impact are High because of the arbitrary command execution. I also included Availability impact because those commands can shut down the system. I will concede though that Attack Complexity could be "very high" if that existed on the Attack Complexity scale. :)
Impact
Someone with control over the website's content can run arbitrary code where ever the synthetics recorded session will be re-executed.
Developer computers and CI systems come to mind. The most realistic attack scenario would be privilege escalation from within a company.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The escaping function only handles single quotes, but the URL is embedded inside a multi-line comment, so comment-closing characters can break out of the comment and inject code.
Impact
An attacker who controls a website's content can run arbitrary commands on developer machines or CI systems wherever the recorded session is re-executed; the `test` feature inside the recorder is limited because `require` is unavailable there.
What the attacker needed
Victim records a session on attacker-controlled site; victim exports and runs the recorded session
The fix
The escaping should handle comment delimiters so URLs cannot break out of comments.
How it was found
- Start Synthetics Recorder and enter the malicious starting URL.
- Click Start Recording; a browser opens to the modified site.
- Click the GitLab icon on the page to trigger a navigation event.
- Close the browser window.
- Click Export to see the generated code containing the injected payload.
- Save the exported file, install the Synthetics runner, and run it to observe the command execution.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
The Synthetics Recorder is a tool that watches you browse a website and writes a script that repeats your actions. It puts the website address into that script inside a comment, which is text the computer is supposed to ignore. A malicious website can choose an address that ends the comment early and adds its own instructions, so the script runs the attacker's code when someone later plays it back.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.