Skip to content
RCE Write-up Advanced

Sleepless Strings: Template Injection in Insomnia

Insomnia, an API client, renders user-supplied template expressions using the Nunjucks engine in many fields, including cookies set by remote servers. An attacker could achieve arbitrary command execution by sending a malicious cookie and then triggering its rendering, or by tricking a user into importing a malicious collection file or pasting a crafted URL.

Marcio Almeida Follow

Published on tantosec.com

As an offensive security services consultancy, our clients ask us to test various types of computer systems. Corporate networks, client-side software, web applications, APIs, and so on.

Marcio Almeida and Justin Steven, on tantosec.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.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Insomnia renders user-controlled input as Nunjucks templates without sandboxing, allowing arbitrary code execution.

Impact

An attacker could achieve arbitrary command execution on the victim's machine, potentially stealing sensitive data or installing malware, and the issue is still remotely exploitable in the latest version of Insomnia as of the time of writing.

What the attacker needed

Victim uses Insomnia; victim sends request to malicious server; or victim imports malicious collection file; or victim pastes malicious URL

The fix

The issue was not fixed; mitigations include not importing untrusted files, inspecting data for template expressions, disabling cookie storing/sending, or patching out Nunjucks rendering.

How it was found

  1. Set up a malicious server that responds with a Set-Cookie header containing a Nunjucks template payload.
  2. Send a request from Insomnia to the malicious server, which stores the cookie in the cookie jar.
  3. Send a second request to the malicious server, causing the cookie to be rendered and the payload to execute.
  4. The output of the executed command is exfiltrated via the cookie value sent to the server.

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 write-up has not been written yet. The Original tab links to the source.

Insomnia is a tool for testing APIs. It uses a template engine called Nunjucks to fill in variables, but it also evaluates any template expressions it finds in many places, including cookies from servers. An attacker can put a malicious template expression in a cookie, and when Insomnia uses that cookie, it runs the expression as code on the user's computer.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.