Skip to content

2.16.33: CSRF tokens on user-data pages, no database errors shown, many fixes

Latest

Choose a tag to compare

@dlangille dlangille released this 14 Nov 12:35
· 33 commits to main since this release

Security

  • CSRF tokens (S4, S6). Every page that changes a user's data now requires a token on a POST: the watch-list icons, watch-list maintenance, port-watch, pkg_upload, customize, report subscriptions, committer opt-in and announcements. Before, a link on another site followed by a logged-in user could change their watch lists. An admin following such a link could publish site-wide HTML as an announcement.
    • The token is an HMAC-SHA256 of the user id, keyed with the new CSRF_SECRET (see Upgrade notes). It is the same on all of a user's devices, so pages cached per user still work.
    • The watch-list icons are small POST forms now. They look and work as before: one click, then back to the same page.
    • An old link or bookmark to watch-list.php, or a link from another site, lands on the "ask" page. Nothing changes until Update is clicked, and Update only goes back to a page on this site.
    • A form left open while CSRF_SECRET changes is refused with "Nothing was changed … Please reload the page and try again."
    • The announcement text is now escaped inside its edit box; a stored </textarea> no longer breaks out of it.
  • No SQL or PostgreSQL error text on pages. About 100 places printed the failed SQL and/or PostgreSQL's error message into the page, for example on /sysutils/?page=99999999999999999999. All now call freshports_QueryFailed(). It logs the error, the SQL and the caller's file and line to syslog. The visitor sees "Sorry, a database query failed. The error has been logged."
  • Watch-list pages, delete-account.php and the other user pages now check the logged-in user, not just the cookie. A stale cookie used to get past the check, and the page ran as user 0.
  • Maintenance mode: pages now stop after the redirect. Before, a POST was still processed in full.
  • MoveStagingToWatchList() refuses a watch list the user does not own.
  • Array cookies and array branch/port parameters (visitor[], ?branch[]=) are ignored instead of causing a fatal error.

Fixes

  • Watch-list icons on watch.php add to or remove from the list being shown. Removing from a non-default list used to do nothing.
  • Watch-list icons show the right state on pkg-message, pkg-plist and USES searches.
  • pkg_upload: the "not in staging area" list checks only the user's own staging area, so ports another user had staged are no longer dropped.
  • WatchListElement::Add() returns -1 when the insert fails, so a failure no longer looks like success.
  • search.php: package searches with "sounds like" or "include deleted ports" work. An unknown stype resets to a port-name search. The Message ID redirect is URL-encoded.
  • commit.php: 404 for an unknown revision (was a fatal error) or an unknown message_id (was a 200).
  • forgotten-password.php: a blank submit shows the form again instead of a fatal error.
  • vuxml.php: ?list&all works, array parameters are ignored, and <html lang> follows the visitor's language.
  • VuXML ranges show both operators as symbols (>= 13.8.0 < 13.8.2).
  • Wrong-case URLs with ?branch= redirect properly (301) instead of showing warnings or a server path.
  • The bot-gate page and HTML_Page2 pages use the visitor's language.
  • Each text size gets its own ETag, so changing the size no longer returns a stale 304 (C5).
  • The legacy news feed cache is written to a temporary file and renamed into place, so readers never get a partly written feed (C7).
  • Port pages: the slave-port note shows in the quarterly tooltip, man page links are encoded (g++13), and the Codeberg placeholder says Codeberg.
  • List pages say "sorted by date added" when they are. categories.php drops the debug row numbers and marks the Last Update sort.
  • graphclick.php: a click that misses a bar goes back to the graph.
  • Small fixes: the watch-list dropdown escapes for HTML only, the class quote on the watch page's category header is closed, and the FAQ "Port Moves" link has https://.

Removed

  • www/filter-setup.php: an unlinked, broken page from 2006. /filter-setup.php now gives a 404.
  • classes/commit_log_ports_ignore.php and classes/ports-unrefreshed.php: unused classes.
  • The unfinished /--/api/1/search/ route. It required a file that never existed, so every visit was a fatal error. It now gives a 404. An API is still wanted: #4.
  • The num, days and dailysummary parameters on the front page and sanity test failures. They were never read.

Translations

  • scripts/i18n-extract.sh now also scans rewrite/. freshports.pot went from 1226 to 1244 msgids and was merged into every .po. About 15 new strings per language are marked fuzzy and show in English until reviewed.

Upgrade notes

On each host, before pkg upgrade:

  1. Set CSRF_SECRET in /usr/local/etc/freshports/constants.local.php (documented in constants.local.php.sample):
    define('CSRF_SECRET', '<output of openssl rand -hex 32>');
    Without it, every change to user data is refused and the reason is logged.

After pkg upgrade:

  1. scripts/i18n-compile.sh, then service php_fpm reload.

Separate from this release: database-schema updates-2026-11-14-migrate-staging-area.ddl fixes MigrateStagingAreaToWatchList(). Run it as postgres on each database.

No nginx changes.

Files added, deleted or renamed since 2.16.32

Added

  • include/csrf.php

Deleted

  • classes/commit_log_ports_ignore.php
  • classes/ports-unrefreshed.php
  • www/filter-setup.php

Renamed

  • none

Full Changelog: 2.16.32...2.16.33