Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically escaping HTML with Hiccup, is it possible?

Tags:

clojure

hiccup

I just tried this with Hiccup:

(hiccup.core/html [:h1 "<script>alert('xss');</script>"])

and to my surprise I got an alert box, Hiccup is not escaping strings by default. I see that there's a method to escape strings, but in my opinion if it's not the default, sooner or later you'll forget and be vulnerable to XSS.

Is there a way in Hiccup to have it escape strings by default?

like image 734
pupeno Avatar asked Jul 11 '15 08:07

pupeno


1 Answers

hiccup 2.0.0-alpha1 has escaping by default. You just need to change the hiccup.core/html call to hiccup2.core/html and it should work without any change.

(str (hiccup2.core/html [:h1 "<script>alert('xss');</script>"]))

I've upgraded my project from 1.0.5 and it's working without any regression.

like image 69
Thiago Lewin Avatar answered Sep 25 '22 19:09

Thiago Lewin