Fossil Forum
Post: Embedded documentation in markdown format allows unsafe HTML
This is a security-relevant bug report. I looked for, but did not find, a better place to report it than here at the forum.
Embedded documentation
(/doc/ URL path prefix)
in markdown format is supposed to be subject to the
safe-html,
which, by default, imposes an allowlist on
what HTML elements may be used.
But it not effective:
the code path that renders markdown documents under /doc/
does not call the safe_html_context function,
which is what consults the safe-html setting,
nor does it call safe_html.
This only applies to embedded documentation served under /doc/:
the same markdown documentation files rendered under /file/ do apply safe HTML.
Here's a demonstration recipe:
$ fossil version
This is fossil version 2.29 [c92989d3a8] 2026-11-15 16:10:52 UTC
$ fossil settings safe-html
safe-html
$ fossil init test.fossil
$ mkdir test && cd test && fossil open ../test.fossil
$ cat >home.md <<EOF
test <i><b>bold</b> emphasis</i>
<style>
body{transform:rotate(2deg);font-family:fantasy;}
.content{font-size:30pt;color:fuchsia;}
</style>
script<script>alert('xss');</script>script
<form id=csrf action="https://example/action" method=POST>
<input type=hidden name=transfer value=1000>
<input type=submit value="Click me">
</form>
EOF
$ fossil add home.md
ADDED home.md
$ fossil commit -m "doc file with evil markup"
$ fossil ui -p /doc/trunk/home.md
The browser will display a page with messed up fonts and formatting,
and a button that tries to send a POST request if clicked.
The <script> element, too, is active in the HTML output.
It fails to run, but only because of CSP:
Executing inline script violates the following Content Security Policy directive 'script-src 'self' 'nonce-9bde964b62ae17e3098d7cb67212e49a07b41c5c4387c959''. Either the 'unsafe-inline' keyword, a hash ('sha256-LMD3+o5SW1nMQnP8eqehN5Cf/fLDXyNLVQ1aWycvx8E='), or a nonce ('nonce-...') is required to enable inline execution. The action has been blocked.
The same file, viewed under the /file/ prefix, applies safe HTML as expected, with the disallowed elements highlighted in yellow and escaped:
$ fossil ui -p /file/home.md
I think it has been the case that embedded markdown documentation allows unsafe HTML ever since the safe-html setting was introduced in checkin 89b6dda99c455333.
I think this is also the root of the problem discussed in forum post , "An HTML comment in a Markdown file is visible in some cases". There, it had to do with a discrepancy in how HTML comments were treated under /doc/ versus under /file/, /tree/, and /dir/. The discussion there had to do with HTML comments, but I believe it's because of a difference in HTML handling more generally.
To verify that safe_html is not being called,
I set a breakpoint in GDB and visited a /doc/ page:
$ gdb --args fossil server --debug-nofork (gdb) break safe_html (gdb) run $ curl http://127.0.0.1:8080/doc/trunk/home.md
Following the call stack for /doc/, here is where
document_render calls markdown_to_html
and does not call safe_html afterwards.
For /file/, here is where
wiki_render_by_mimetype calls markdown_to_html
and follows it with a call to safe_html.
This is a security-relevant bug report. I looked for, but did not find, a better place to report it than here at the forum.
David, you know this from our email but for the sake of future folks: we're not adverse to security-related posts and appreciate the sentiment behind preferring email. Either are fine. For folks who prefer email, drh sqlite org (project lead) is primary contact and those who trust me enough to do so are welcome to add me to the mail (stephan wanderinghorse net), noting that it'll possibly land in my inbox indirectly anyway.
Thank you for the detailed report!
This is a security-relevant bug report. I looked for, but did not find, a better place to report it than here at the forum.
David, you know this from our email but for the sake of future folks: we're not adverse to security-related posts and appreciate the sentiment behind preferring email. Either are fine. For folks who prefer email, drh sqlite org (project lead) is primary contact and those who trust me enough to do so are welcome to add me to the mail (stephan wanderinghorse net), noting that it'll possibly land in my inbox indirectly anyway.
Fixed in . (edit: fix the link)
Thank you for the detailed report!