Skip to content

Release v1.0.2-beta

Choose a tag to compare

@ClearanceClarence ClearanceClarence released this 12 Jun 09:49
· 6 commits to main since this release

Ledger 1.0.2-beta is a security and polish release. A full self-audit of the codebase turned up a handful of real issues — the most serious being that X-Forwarded-For was trusted as the client IP (spoofable, which bypassed the IP allowlist and brute-force lockout), that read-only mode could be slipped past via the EXPLAIN endpoint and comment-prefixed writes, and that the Saved Queries feature was outright broken by a dropped function signature. All fixed here.

On top of the security work: the keyboard-shortcut overlay was rebuilt with live search, the update check moved to a server-side proxy, the update notification became a corner toast, a proper favicon set shipped, and the force_https setting can no longer lock you out.

The feature set from 1.0.1-beta is unchanged. No breaking changes. If you're on 1.0.1-beta, this is a drop-in upgrade.

🔒 Security

X-Forwarded-For is no longer trusted by default

getClientIp() consulted X-Forwarded-For and X-Real-IP before REMOTE_ADDR. On a direct deployment those headers are fully attacker-controlled, so the value Ledger used as "the client IP" could be spoofed — which defeated three things at once:

  • IP allowlist — send X-Forwarded-For: <an-allowlisted-ip> and walk straight through it.
  • Brute-force lockout — rotate the header each request and the per-IP counter never trips, so login attempts are effectively unlimited. (Spoofing a victim's IP could also lock the victim out.)
  • Audit log — the recorded source IP was whatever the attacker chose.

Forwarded headers are now honored only when the request originates from an IP in the new trusted_proxies config list, and the left-most entry is validated with filter_var(..., FILTER_VALIDATE_IP). The list is empty by default, which means forwarded headers are ignored entirely. Configure it under Settings → Trusted Proxies if Ledger sits behind a reverse proxy.

Read-only mode hardened

Three gaps closed:

  • Stacked queries are blocked at the driver (MYSQL_ATTR_MULTI_STATEMENTS=false), so EXPLAIN SELECT 1; DROP TABLE x can't smuggle a write through the explain endpoint.
  • The explain_query AJAX action gained the same read-only guard every other write path already had — it previously accepted raw SQL with no check.
  • isWriteQuery() now strips leading SQL comments before keyword-matching and recognizes writing CTEs (WITH … DELETE …). Both /* */ DELETE … and WITH x AS (…) DELETE … previously slipped past as non-writes.

The keyword heuristic is still a heuristic; for a hard boundary, run Ledger with a grant-limited read-only MySQL user.

Stored XSS in the Processes view

Every field in the process-list row was HTML-escaped except the database name, which can legally contain markup (CREATE DATABASE accepts almost anything in backticks). A database named with an onerror payload would execute when an admin opened the Processes tab. Now escaped like the rest. The shared escapeHtml helper in ledger.js was also aligned with the other two copies to escape single quotes.

Other hardening

  • DSN parameter injection guarded. The db request parameter is rejected if it contains ; or control characters before being interpolated into the PDO DSN.
  • TOTP codes can't be replayed. A valid 2FA code was accepted for its full ±1 step (~90 s) window with no record of use. The matched time-step is now burned per-user, so a captured code can't be reused within its window.
  • Lockout state moved out of system temp. Failed-attempt tracking lived in sys_get_temp_dir(), world-readable on shared hosts. It now lives in the web-protected logs/ directory.
  • Legacy plaintext credentials auto-upgrade to bcrypt. A hand-edited plaintext password in config.php still logs in once, then is silently rewritten as a bcrypt hash so it never persists as plaintext.

🛠 Fixed

Saved Queries no longer fatals

A dropped function ledger_saved_queries_file(): string signature left the function undefined while the rest of the file still parsed. Every saved-query action (save, list, update, delete) returned a 500 / malformed JSON — the whole feature was dead on arrival. Restored.

force_https can no longer lock you out

Enabling "Force HTTPS redirect" on a server with no working HTTPS listener (e.g. default XAMPP, no 443) previously 301'd every request to an unreachable https:// URL. Because the redirect was a permanent 301, browsers cached it indefinitely — so even after fixing config.php the browser kept auto-redirecting out of its own cache until cleared.

Three fixes: the redirect is now a 302; the setting can only be enabled from an already-HTTPS session (proving HTTPS works before committing to it); and the Settings checkbox is disabled over plain HTTP with an inline explanation, so you learn about the constraint before clicking Save.

Latent ReferenceError in the update banner

A fallback path in the old banner-rendering code referenced an undefined repo variable. Never triggered in practice (the upstream always supplied a URL) but would have crashed if it hadn't.

✨ New Features

Keyboard-shortcut overlay rebuilt

The ? overlay was a full rewrite:

  • Live search at the top — matches key labels, descriptions, and section names (searching sql pulls in the entire SQL Editor section), autofocused on open.
  • Single-column layout so descriptions get the full row width and no longer wrap mid-phrase.
  • Platform-aware keys — ⌘ ⇧ ⌥ ⏎ on Mac (detected via navigator.platform), with a hint line saying which set is shown.
  • Command-palette Esc behavior — first Esc clears the search, second closes the overlay.
  • Empty state when search returns nothing, and a mobile-stacked layout under 600px.

Favicon set

Previously no favicon link existed in any head section, so browsers showed the default globe. Ships the three-bar ledger mark on a rounded-square green background:

  • Light (#16a34a background, white bars) and dark (#4ade80 background, dark bars) variants, selected via prefers-color-scheme.
  • 32px PNG fallback for older browsers, 180px apple-touch-icon for iOS home-screen pins.
  • Wired into all four head sections: main UI, installer, login, and 2FA verification.

🎨 Changed

Update check runs through a server-side proxy

The browser previously fetched tryledger.dev/api/version.json directly via CORS, which failed silently whenever a CDN stripped the CORS headers — and exposed every admin's IP to the endpoint. The browser now calls a same-origin ajax.php?action=check_update, handled by a new UpdateCheck class that:

  • Caches the upstream response in logs/version-cache.json for 24 hours.
  • Fetches server-side via cURL (with a file_get_contents fallback) when stale, sending no cookies and no referer.
  • Serves stale cache marked stale:true if the upstream is down, so the banner survives an outage.
  • Runs before the DB connection, so the notification still works when MySQL is down.

Net effect: one outbound request per install per day instead of one per browser per day, and the same-origin fetch can't be blocked by CORS or stripped by a CDN.

Update notification is now a toast

The full-width banner that pushed page content down was replaced with a small top-right toast — slide-in animation, pulse dot, theme-driven colors across all 20 themes. Security updates get a distinct amber treatment and omit the dismiss button (security updates demand action, not dismissal). Respects prefers-reduced-motion.

📦 Deployment

  • nginx config shipped. The repo only carried an .htaccess, so on nginx none of the file protections applied — GET /logs/queries.log would serve the query history as plaintext. Added nginx.conf.example mirroring the Apache rules, plus a deny-all logs/.htaccess as belt-and-suspenders.
  • .gitattributes added pinning all text files to LF, so Windows checkouts stop producing phantom LF↔CRLF churn in diffs.

⚙️ Internal

  • Auth::getClientIp() — defaults to REMOTE_ADDR; only reads forwarded headers from a configured trusted_proxies IP, taking and validating the left-most entry.
  • Auth::isWriteQuery() — strips leading comments and detects writing CTEs before the keyword match.
  • LedgerTOTP::verifyAt() — new method returning the matched time-step, used by Auth to burn used steps and reject replays.
  • Database::connect() — sets MYSQL_ATTR_MULTI_STATEMENTS=false and validates the db name against DSN injection.
  • UpdateCheck — new class backing the server-side update proxy with disk caching and a stale-cache fallback.

⚠️ Known Issues

  • The read-only keyword heuristic isn't a hard boundary. It now resists the known bypasses, but classifying SQL by string-matching in PHP will always be best-effort. For an enforced boundary, connect Ledger with a read-only MySQL account.
  • Very large imports are still slow even with fast mode on. Carried over from 1.0.1-beta — a 1.6M-statement dump projects ~10–15 minutes on a typical server. The limit is PHP↔MySQL round-trip latency; use the mysql CLI (mysql < dump.sql) for multi-gigabyte dumps.
  • upload_max_filesize and post_max_size in php.ini still cap what PHP will accept. Raise these for larger uploads, or use the CLI.

🚀 Install

cd /path/to/htdocs
git clone https://github.com/ClearanceClarence/Ledger.git ledger

Open http://localhost/ledger/ and follow the 3-step installer.

Or download the Source code (zip) below, extract it into your web root, and open it in a browser.

For Docker, see [DOCKER.md](https://github.com/ClearanceClarence/Ledger/blob/main/DOCKER.md).

🔄 Upgrading from 1.0.1-beta

No breaking changes. To upgrade:

cd /path/to/ledger
git pull

Or for zip-based installs: extract the new release over your existing files (keep config.php and the logs/ directory).

No database migrations. No config changes required. Existing sessions, saved queries, ER diagram layouts, and query history are preserved.

One optional config note: if you run Ledger behind a reverse proxy and rely on the IP allowlist, add your proxy's IP to the new trusted_proxies list (Settings → Trusted Proxies). Without it, forwarded headers are ignored and the allowlist will see the proxy's IP instead of the real client — which is the safe default, but may not be what you want behind a trusted proxy.

If you have Check for updates enabled (default), 1.0.1-beta installs will see a banner pointing at this release within 24 hours.


Pure PHP + vanilla JS. Zero dependencies. Drop-in install.

Full changelog: [CHANGELOG.md](https://github.com/ClearanceClarence/Ledger/blob/main/CHANGELOG.md)