You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Database isn't escaped when dumped in the published HTML file #1100
This might result in broken HTML, in my case because of a closing </script> tag in the note body.
To Reproduce
Something like this is enough to break it
* <script> BOOM </script>
Steps to reproduce the behavior:
Add the note above, reindex
Publish HTML (make sure to make the page public)
Open HTML in browser (doesn't matter if just as HTML file or via actual local webserver)
You'll see Uncaught SyntaxError: "" literal not terminated before end of script in the logs and generally it won't load properly
Expected behavior
Not sure how to fix this properly.. I messed with JSON stringifying a bit, but it didn't work for some reason. Would be happy for pointers what's the best way to escape and fix it.
Yeah it could be a potential security risk. IMO best to use some existing node/clojure library to handle this, even if you handle script tag, other tags can break it as well, and escaping is not something fun to maintain
@karlicoss I copied some code from hiccup which should resolve most issues related to escaping the publishing HTML, I just tested it and it works for several of my graphs, let me know whether it works for you.
PR: #1134
Activity
tiensonqin commentedon Jan 13, 2021
@karlicoss Yes, we need to espape the data for
window.logseq_db, something like this:https://github.com/logseq/logseq/blob/master/src/main/frontend/publishing/html.cljs#L53
And, when loading the publishing the exported HTML, we need to unescape the data, something might like this:
The difficult part to me is how to escape the string properly, something like this might work for the
<script>tag:But what about other cross-site scripting vulnerabilities? I guess we don't need to worry too much for self-hosted digital garden 😁
karlicoss commentedon Jan 14, 2021
Yeah it could be a potential security risk. IMO best to use some existing node/clojure library to handle this, even if you handle script tag, other tags can break it as well, and escaping is not something fun to maintain
fix: Database isn't escaped when dumped in the published HTML file
tiensonqin commentedon Jan 15, 2021
@karlicoss I copied some code from hiccup which should resolve most issues related to escaping the publishing HTML, I just tested it and it works for several of my graphs, let me know whether it works for you.
PR: #1134
fix: Database isn't escaped when dumped in the published HTML file
tiensonqin commentedon Jan 18, 2021
Closing this now.