Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
Kwpolska
· 1y ago · 0 comments
All JSON serializers worth their salt can serialize a single string to JSON, so the simplest way is to do json.dumps(the_string) and mark the string as safe so that it doesn't get escaped twice.
Comments
[–]
GICodeWarrior
1y ago
Simple JSON encoding alone is not sufficient if you put the output into a <script> tag.
<script>const user_input = "</script><script>alert(1)//"; ...