Re:The Invisible JavaScript Backdoor
by kuon on Wednesday November 10, 2021 @07:57AM
(#29174141)
My editor (vim) will warn me with a loud visual red block for any non ascii char outside a string literal. But I do not think that is enough. Compiler and interpreter must be more strict.
[ Parent
| on HN ]
That's not the default vim configuration though.
Mind sharing the relevant config line?
I thought this was default but just realised it only does the <FFFF> thing when there is no printable glyph available.
Allowing printable unicode in strings seems like a nice balance if it can be done reliably.
Re:The Invisible JavaScript Backdoor
by fatheart on Wednesday November 10, 2021 @10:34AM
(#29175749)
After seeing this thread I added the following to my vimrc:
highlight link NonASCII Error
autocmd Syntax * :syntax match NonASCII "[^\d0-\d127]"
Obviously haven't been using it long, and I'm not confident enough in my vim knowledge to vouch for its correctness, but it works in the limited amount of scenarios I tested so far.Sure:
fun! HighlightNonAscii()
if &ft =~ 'markdown\|text'
return
endif
syntax match nonascii "[^\x00-\x7F]"
highlight nonascii guibg=#ff2232 guifg=#000000
endfun
autocmd BufEnter * call HighlightNonAscii()
Your version might depend on your frontend (gui, terminal...). And you might want to filter more file types.
Re:The Invisible JavaScript Backdoor
by jrochkind1 on Wednesday November 10, 2021 @08:17AM
(#29174290)
I'm surprised VS Code doesn't at least have that option. (Or does it?)
It has `editor.renderControlCharacters` but only recently started displaying few dangerous previously invisible ones (directional overrides) natively [1], but besides that you had to use extension that adds highlights for non-ascii non-whitelisted [2] or predefined [3] characters.
[1] https://github.com/microsoft/vscode/issues/116939 [2] https://marketplace.visualstudio.com/items?itemName=nachocab... [3] https://marketplace.visualstudio.com/items?itemName=nhoizey....