When HyperDoc’s fedwiki catalog loader fetches remote .../system/sitemap.json, it assumes the response is JSON and calls shasht:read-json unconditionally. If a remote site returns an HTML error page (first non-whitespace char is <), SHASHT signals SHASHT-INVALID-CHAR and the condition is not caught by the handler-case in the background thread. With --disable-debugger, this aborts the process and brings down the server.
This is easy to hit with transient upstream failures, redirects, captive portals, misconfigured sites, or "friendly" error pages.
Environment
- SBCL 2.4.10 (reproduced on macOS + Nix dev shell)
- HyperDoc running via
./start.sh - CLOG + Hunchentoot + Clack/Hunchentoot handler (as currently shipped in this repo)
Steps to reproduce
-
Start server:
./start.sh -
Ensure fedwiki integration loads one or more sites where
http://<site>/system/sitemap.jsonreturns HTML (e.g., an error page, proxy page, redirect page).-
In my logs, examples were:
http://ims.obeya.xyz/system/sitemap.jsonhttp://marc.obeya.xyz/system/sitemap.json
-
-
Observe server abort shortly after "New connection id ...".
Actual behavior
Server aborts with an unhandled condition in a background thread, then fails to shut down cleanly.
Representative log excerpt
Unhandled SHASHT:SHASHT-INVALID-CHAR ...:
Unexpected character #< found during parsing.
...
(HYPERBOOK/FEDWIKI::FETCH-JSON "http://ims.obeya.xyz/system/sitemap.json")
(HYPERBOOK/FEDWIKI::FETCH-SITEMAP ...)
...
unhandled condition in --disable-debugger mode, quitting
Expected behavior
- Remote fetch failures (including non-JSON responses) should not crash HyperDoc.
- The failing wiki entry should be marked as failed/unreachable with a stored status condition, and the server should continue running.
Probable cause
fetch-jsoncallsshasht:read-jsonon the HTTP stream without validating content-type or first character.make-fedwikiwraps the refresh in ahandler-casethat catches only stream/usocket/drakma-ish conditions but does not catch parser errors (shasht:*) or genericerror.
Proposed fix (minimal)
- Extend
make-fedwiki’shandler-casewith a final(error (c) (setf (status-of wiki) c))clause so unexpected conditions never abort the process. - Improve
fetch-jsondiagnostics by peeking the first non-whitespace character and raising a clear error when the response starts with<(HTML), e.g. "Expected JSON from ... but got HTML".
Notes
This is not about "bad data" per se; it’s about robustness: remote federation endpoints can and do return HTML in error modes, and we should treat that as a normal failure case, not a fatal crash.