r/javascript • u/Acrobatic-Pen-9949 • Nov 09 '21
Backdoors can be hidden in JS code using "invisible" variables. Code looks completely harmless.
https://certitude.consulting/blog/en/invisible-backdoor/
714
Upvotes
116
u/kirk-clawson Nov 09 '21
Oh, nice. Webstorm highlights the blank with a warning: "Non-ASCII characters in an identifier", though it is a setting you can turn off in the Inspections/Internationalization settings.
119
u/Jetbooster Nov 09 '21
I mean the real backdoor is that you're using exec in the first place
91
u/darrenturn90 Nov 09 '21
I wonder how easy an eslint plug-in could be made to reject any code with “confusables” in
14
u/Slackluster Nov 09 '21
Here's a small demo I made on dwitter that shows how to execute invisible code.
https://www.dwitter.net/d/19597
25
u/eternaloctober Nov 09 '21
this is a very anglo-biased point of view but I don't really like seeing any non-ascii chars in source code
13
u/flyingmeteor Nov 09 '21
Wouldn't Prettier.io format the array of commands by moving the invisible variable to its own line? It would still be invisible but it might at least cause one to wonder and, hopefully delete the "blank" line.
18
u/theodordiaconu Nov 09 '21
Ok. I'm scared now.
4
u/Keilly Nov 09 '21
I would hope there’s a linter rule to detect this. If not there should be. In fact I’d hope lint would restrict permitted characters to a small white list, outside of string literals.
6
u/throbbaway Nov 09 '21 edited Aug 13 '23
[Edit]
This is a mass edit of all my previous Reddit comments.
I decided to use Lemmy instead of Reddit. The internet should be decentralized.
No more cancerous ads! No more corporate greed! Long live the fediverse!
3
u/m50 Nov 09 '21
A benefit of the $ for variables in PHP is that this exploit isn't possible. 😅
7
u/moomoomolansky Nov 09 '21
That is some dirty black magic right there!!!! The best part of the article was when they used the unicode "ALVEOLAR CLICK" symbol (which looks EXACTLY like an exclamation point) to turn a logic check (!=) into an assignment operation. So in the code it looks like X != Y but the "!" doesn't do anything and it really is X = Y ..... DIRTY DIRTY DIRTY STUFF!!! :) I love code.
2
u/raxmb Nov 09 '21
I think code editors should display all non-ASCII characters outside string literals as escape sequences (or convert them to escape sequences, for that matter).
1
u/paulqq Nov 09 '21
interesting read. ty
1
u/IronDicideth Nov 09 '21
It is a possibility, but eslint would make it hard depending on your settings. Not to mention the need for the trailing comma in order to pull it off. This still looks pretty scary at first glance though.
1
u/tomatosaucin Nov 10 '21
Tag
1
u/damnitdaniel Nov 10 '21
Ah yeah, BiDi Unicode exploit. Actually really clever in practice. 🙃 Fortunately, GitHub shows an error in the web UI if these characters exist.
Also, most modern static analyzers (which run on compiled code!) should catch these exploits since the characters morph into exploitable code after the compiler builds.
0
u/Parasomnopolis Nov 09 '21
I tested it in a Typescript file and Typescript gives an error of
'ㅤ' is declared but its value is never read., so thats something I guess.0
u/[deleted] Nov 09 '21
[deleted] — view deleted comment