Skip to content
XSS Write-up Intermediate

When Your Terminal Lies: Exploiting ANSI Escape Sequences in HTTP

HTTPie prints HTTP response headers and text bodies to the terminal without neutralising ANSI escape sequences, so a malicious server can inject control sequences. An attacker could clear the screen, show a fake sudo prompt, mask hyperlinks, or trigger terminal features like clipboard writes and notifications.

Ajith Prabhu Follow

Published on medium.com

Most of us think of a terminal as little more than a text viewer. A command runs, some text appears on the screen, and we instinctively trust what we see.

Ajith Prabhu, on medium.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

Likely the application treats decoded HTTP response data as plain text and does not strip or escape terminal control sequences before writing to stdout.

Impact

An attacker could manipulate the terminal to phish for passwords, spoof hyperlinks, or trigger clipboard and notification features, though the impact depends on terminal support for the injected sequences.

What the attacker needed

Attacker controls HTTP server; victim uses HTTPie interactively; terminal supports escape sequence

The fix

HTTPie should sanitise or escape terminal control sequences in response headers and bodies before writing them to the terminal.

How it was found

  1. Set up a malicious HTTP server that returns responses containing terminal escape sequences.
  2. Have the victim use HTTPie in its default interactive mode to request a resource from that server.
  3. The terminal interprets the injected sequences, for example clearing the screen and displaying a fake sudo prompt.

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.

A terminal is not just a text viewer; it interprets special control codes called escape sequences that can move the cursor, clear the screen, or create clickable links. HTTPie, a command-line tool for making HTTP requests, passes server responses to the terminal without removing these codes. A malicious server can therefore send hidden instructions that the terminal obeys, tricking the user.

What is XSS?

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

More by Ajith Prabhu

View all

2 more disclosed reports, best first.

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.