📖 ~4 min read • Source: FreeBSD VuXML
VuXML topic: mdbook — XSS in mdBook's search page
Related CVEs: CVE-2020-26297
Upstream summary: Rust Security Response Working Group reports: The search feature of mdBook (introduced in version 0.1.4) was affected by a cross site scripting vulnerability that allowed an attacker to execute arbitrary JavaScript code on an user's browser by tricking the user into typing a malicious search query, or tricking the user into clicking a link to the search page with the malicious search query prefilled. mdBook 0.4.5 fixes the vulnerability by properly escaping the search query.
Table of contents
Symptom & Impact
mdbook on FreeBSD 15 runs only when something invokes it, so there is no crash loop and no failed unit to notice — the exposure is input-driven. A developer build, a CI job, a package rebuild or triage tooling that runs objdump, readelf or gdb across an untrusted binary can hit a malformed section header and corrupt memory inside the toolchain process, running code as the build user. On a shared builder or CI runner that means tampered build output rather than downtime. mdbook is a build-time developer tool that exits when the command finishes, so there is no service to restart — only in-flight builds and long-lived helpers such as distcc or clangd still hold the old binaries.
Environment & Reproduction
Reproduction targets FreeBSD 15. Confirm with freebsd-version -kru, uname -a, and the installed package via pkg info mdbook and pkg query "%n-%v" mdbook. Capture system state with pkg audit -F and service -e. Trigger the workflow that exposes mdbook while collecting tail -200 /var/log/messages, dmesg -a, and /var/log/pkg.log.
Root Cause Analysis
Root cause is tracked at FreeBSD VuXML. The FreeBSD ports security team shipped a corrective mdbook port revision; hosts on an outdated build remain exposed. Correlate /var/log/pkg.log with /var/log/messages and kernel state in sysctl kern.lastpid + sysctl kern.osreldate to isolate the change that triggered the failure mode.
Quick Triage
Quick triage: tail -100 /var/log/messages, pkg audit -F, pkg version -v mdbook, and pfctl -sr (or ipfw list) to confirm firewall posture. For kernel issues: dmesg -a | tail -100 and kldstat.
Step-by-Step Diagnosis
1) service -e to enumerate failed services. 2) tail -F /var/log/messages and dmesg. 3) Validate firewall via pfctl -sr -v or ipfw show. 4) pkg check -B mdbook for integrity. 5) pkg install -fy mdbook to reinstall if tampered. 6) Correlate findings with /var/log/pkg.log and FreeBSD VuXML to pin the commit that introduced the regression.
Solution – Primary Fix
Primary fix: install the corrective mdbook port revision referenced by FreeBSD VuXML. Typical commands: sudo pkg update, sudo pkg upgrade mdbook (or sudo pkg upgrade -y for the whole system), then and pkg audit to confirm no remaining advisories. For ports tree builders: sudo portsnap fetch update + cd /usr/ports/<cat>/mdbook && sudo make deinstall reinstall clean. Reboot if the kernel module is involved.
Need help rolling this patch across a FreeBSD fleet? Our IT Solutions & Services team manages FreeBSD jail/bhyve patch windows. Get in touch for a free consultation.
Solution – Alternative Approaches
Alternatives include locking the package with sudo pkg lock mdbook until vetted, downgrading via pkg install <older-version> from a pinned repo, switching the FreeBSD pkg repository between quarterly and latest in /usr/local/etc/pkg/repos/FreeBSD.conf, isolating the affected service in a jail (iocage/bastille) with stricter firewall rules, or replacing the service with a vendored static build for the period between exposure detection and full rollout.
Verification & Acceptance Criteria
Acceptance: pkg info mdbook shows the expected fixed version is running, pkg audit returns no advisory for mdbook, tail -50 /var/log/messages shows no errors after restart, and the original reproduction for mdbook no longer triggers across two consecutive runs.
Rollback Plan
Capture state with pkg query "%n-%v" > /root/pkg-pre.txt and a ZFS boot-environment snapshot: bectl create pre-mdbook-patch. To revert, run sudo pkg install -f <previous-version> or boot the previous BE via bectl activate pre-mdbook-patch && reboot. For kernel/loader changes, drop to the loader prompt and select the previous boot environment.
Prevention & Hardening
Prevent recurrence by scheduling pkg audit -F via periodic.conf (daily_status_security_pkgaudit_enable="YES"), subscribing to freebsd-security-notifications, mirroring through a local pkg repo managed by poudriere, version-pinning sensitive packages with pkg lock, enabling automatic ZFS BE snapshots before upgrades, and monitoring file integrity via mtree or aide. Apply the CIS FreeBSD hardening checklist where applicable and harden jails with allow.* tunables in /etc/jail.conf.
Related Errors & Cross-Refs
Related issues that commonly surface alongside mdbook: pkg lock contention, mismatched ABI after kernel/userland skew (freebsd-version vs uname -K), pf rule drift, and stale shared-library references after upgrade (pkg check -d).
View all freebsd-15 tutorials on the Tutorials Hub →
Browse all common problems & solutions on the Tutorials Hub.
References & Further Reading
Primary reference: FreeBSD VuXML. Supporting docs: FreeBSD Handbook, man pkg, man freebsd-update, man pfctl, man ipfw, man bectl, man periodic.conf, the FreeBSD Security Advisories at security.freebsd.org, and /usr/ports/UPDATING for port-specific notes implicated in this advisory.