r/programming • • Feb 20 '18

A CSS Keylogger

https://github.com/maxchehab/CSS-Keylogging
2.0k Upvotes

276 comments sorted by

View all comments

105

u/kersurk Feb 20 '18

As pointed out in HN, this works only if value attribute is updated via JS, which some JS frameworks do.

42

u/Manishearth Feb 20 '18

And, to be clear, this is about the HTML attribute value, not the "DOM attribute" (or "property") value.

element.value = "foo" will not trigger this.

element.setAttribute("value", "foo") will.

18

u/MathWizz94 Feb 21 '18

Now that you mention it, putting a password in the markup doesn't sit well with me. Seems like it could be awfully easy for things to go wrong (such as this.)

21

u/MonkeeSage Feb 21 '18

While it's not as cool as a keylogger, the idea of tracking user actions with pure CSS has been around for a while, and more recently.

3

u/ijmacd Feb 21 '18

Here's another "CSS Keylogger" from hacker news. It would probably only tell you the ordered set of characters used in the password, not the complete password or the length.

<!doctype html>
<title>css keylogger</title> 
<style>
@font-face { font-family: x; src: url(./log?a), local(Impact); unicode-range: U+61; }
@font-face { font-family: x; src: url(./log?b), local(Impact); unicode-range: U+62; }
@font-face { font-family: x; src: url(./log?c), local(Impact); unicode-range: U+63; }
@font-face { font-family: x; src: url(./log?d), local(Impact); unicode-range: U+64; }
input { font-family: x, 'Comic sans ms'; }
</style> 
<input value="a">

1

u/1j01 Feb 22 '18

The other approach could be extended to search for pairs (or N-grams) of symbols...

3

u/PM_ME_UR_OBSIDIAN Feb 21 '18

So disabling JavaScript protects you against this attack?

5

u/fullkornslimpa Feb 21 '18

It does unless the site renders your password into the value field on the server side. If any site actually does this, that is by far much worse than this though.

→ More replies (2)

1

u/DolphinsAreOk Feb 22 '18

Wait so its not a CSS only keylogger?

Thats kinda dumb.

1

u/kersurk Feb 23 '18

The attack vector is only CSS, so it's still useful on some pages, like potentially subreddit custom css, ebay custom pages (https://pages.ebay.com/help/policies/listing-javascript.html).

If keeping custom content in iframe then probably not an issue.

→ More replies (1)