# Changelog ## 0.4.1 (2026-10-29) - **`auth.auth_delay` failed with an error when `auth_delay` was loaded.** `current_setting('auth_delay.milliseconds')` returns the value with its unit (`500ms`), and the cast to `int` broke the rule; every report of a server with `auth_delay` showed one error instead of a result. The rule now reads the raw value from `pg_settings.setting`. Tested with PostgreSQL 18 (`500` → pass) and 14 (loaded, `0` → finding). - **The comparison (`-f`) matched `pg_hba.conf` findings by line number.** A line inserted or removed above turned every open finding below it into "fixed" and "new". The hba rules now return the line's selector (`hba_key`: file, type, databases, users, address and netmask — not the method, so a changed method stays the same line; for `hba.errors` the file and the error text), and the comparison matches a rule by it where all its findings in both reports carry one. Lines with the same selector pair first by equal line number, the rest in their order; what is then left on both sides pairs by line number where only the address differs, so a line narrowed in place that still has the finding stays open rather than "fixed" and "new", while a line replaced by one for other databases or users counts as "fixed" and "new" (for `hba.errors`, a different error). Reports of 0.4.0 and earlier carry no selector and stay matched by line number. Reports gain two fields on hba findings: `hba_key` and, for the rules `apply` changes, `hba_file`. Tested with PostgreSQL 14, 16 and 18: after inserting a line at position 3, nothing fixed, nothing new, every hba finding still open under its new number. - **`hba.host_without_tls` also reported lines that an earlier `reject` line fully covers.** A line behind `hostnossl … reject` or `host … reject` cannot be reached without TLS. Covered means: the reject line comes first in evaluation order (`rule_number` from PostgreSQL 16, which counts included files; the line number before), its databases include the line's (`all` does not include `replication`), its users include the line's (or are `all`), and its address is `all`, the same, or a network of the same family that contains the line's network. Host names and keywords such as `samenet` are covered only by `all` or the identical entry. Tested with PostgreSQL 16 and 18 (with an included file) and 14 against a `pg_hba.conf` with eighteen lines. - **`apply` treated lines from included hba files as lines of `pg_hba.conf`** (PostgreSQL 16 and later). A finding carried only its line number, so the plan aimed at the line with that number in the main file; the check of the expected form or the comparison with `pg_hba_file_rules` afterwards would have stopped the run and restored the file (per `editHba`/`compareHba`, not reproduced), so nothing wrong would have stayed in place, but `apply` could not run as long as an included file had a finding. Findings now carry their file (`hba_file`), and `apply` leaves out every line it cannot confirm as one of `pg_hba.conf`, with a note to change it by hand. Tested with PostgreSQL 16 (dry run): the main file's line planned, three lines of the included file left out; with 14 the main file's line planned. - **`hba.superuser_remote` could miss a remote superuser line (found in the review of this release).** It took the evaluation order from the line number, also across included files (PostgreSQL 16+), counted a `reject` for `::/0` as covering IPv4 lines and one for `0.0.0.0/0` as covering IPv6 lines, and counted `all` in the reject line as covering `replication`, which PostgreSQL never matches with `all`. It now uses the same order as `hba.host_without_tls`, a `reject` for all addresses of one family covers only lines of that family, `all` does not cover `replication`, and a `reject` for exactly the same address covers as well. Also tested with PostgreSQL 14 and 18: `host replication postgres` behind `host all all 10.0.0.0/8 reject` is reported, `host all postgres 10.0.0.0/8` behind it is not. Tested with PostgreSQL 16 and 18: a superuser line at line 18 of an included file, evaluated before a `reject` at line 17 of `pg_hba.conf` and after a `hostnossl … ::/0 reject`, is now reported. - Found while preparing the seminar "PostgreSQL Security und Härtung". ## 0.4.0 (2026-10-29) - **Security fix — update if you run pg-harden as administrator on Windows.** Affected: 0.3.0 to 0.3.2 on Windows. Windows has no identity switch, and these versions checked the way to a file only once before the run (`realpath`) — not when reading or writing, and PHP's `realpath` returns a junction to a volume path (`\\?\Volume{…}`) unresolved, as a path inside the directory (measured with PHP 8.4.6 on Windows 11, build 26300). An account that owns or may write the server's data directory (the service account, or a database superuser via `COPY … TO PROGRAM`) or the profile examined by `client --user` could therefore put a junction on that way: - `apply` and `rollback` then created, overwrote or removed files with administrator rights in the directory the junction pointed to. The names are those of the run — the server's `config_file` and `hba_file`, and `90-pg-harden.conf` in the include directory (`conf.d` or `include_dir`), which may be created or removed as well — but the content is largely the account's: its own configuration files, lines kept from an existing `90-pg-harden.conf`, or a backup that `rollback` (or the restore after a failed run) copies between two files of the same name — also from a file the account may not read into one it can, or from its own file into another cluster's (for example a `pg_hba.conf` with `trust`). - `client --user=` read files below the profile through it with administrator rights; the report then showed findings from a file the account may not read (places and kinds of finding; no passwords or other secrets are printed). `check` read ACLs of the server's files (`log_directory`, `ssl_key_file`, `hba_file`, `ident_file`) by path and reported the ACL of the junction's target as the server's. The way it works now is described in the Windows entry below: reads check the final path before and after reading, writes hold every directory on the way open against renaming, and the target file itself from the check until its write is done. Derived from the code of 0.3.2, not reproduced against 0.3.2 separately; the junction cases of `tests/windows-admin-test.ps1` and `tests/windows-redirect.php` cover 0.4.0. The same code paths exist since 0.3.0. Linux and other Unix systems are not affected by this fix (see 0.3.1 and 0.3.2). - **Windows write side: the target file is held as well (found in the review of this release).** Between the check of the way and the write, `apply` and `rollback` held only the directories; in the data directory, held with `FILE_SHARE_WRITE` for the server, an account with the right to create symbolic links (developer mode or `SeCreateSymbolicLinkPrivilege`) could rename the target file away and put a symbolic link in its place, or put one at the name of a file about to be created. `WindowsPin::verifyTarget` now also opens an existing target file as the entry itself (`FILE_FLAG_OPEN_REPARSE_POINT`, refused if it is a link or a directory, final path checked), and a new one is made there by the helper (`CREATE_NEW` on the entry itself, so a link at the name makes it fail instead of being followed); either is held without `FILE_SHARE_DELETE` until the write is done, writing stays possible. The handle needs `FILE_READ_DATA`: one with attribute access only takes no part in the sharing check, and the file could still be renamed (measured). Removing an entry (`rollback` of a created file) is not held, since removing a link removes only the link. Test: `tests/windows-redirect.php` (65 cases; the one with a symbolic link at the name runs only where the account may create one, such as an elevated PowerShell). - **Run logs (`apply.html`, `rollback.html`) carry a note on personal data in their header:** the confidentiality note adds "Rollennamen können personenbeziehbar sein; nach Abschluss zeitnah löschen." The run logs carry no legal notice, which is where the report says this. - **Command line recut: `-o` writes the report, `-f` compares with an earlier one (breaking, no aliases).** One way to get a report out of `check` and `client` instead of `--format`, `--out` and a separate command: without `-o` the text report goes to the terminal as before; `-o NAME` (`--output`) writes `NAME.json` and `NAME.html` and the terminal names the files and the number of findings. A name ending in `.json`, `.html`, `.htm` or `.txt` writes only that file; any other dot belongs to the name (`-o audit.261028`). `-f NAME` (`--file`) reads `NAME.json` (or `NAME` if it ends in `.json`; HTML and text are refused) and adds the comparison (fixed, new, still open, not comparable) — `verify --previous=x.json` is now `check -f x` or `client -f x`; the command decides the mode, a client report given to `check` (or the other way round) is refused. Placeholders as in PostgreSQL's `log_filename` put the start of the run into the name (`%Y %y %m %d %H %M %S`, `%%`; `-o audit.%y%m%d`), no separate switch; an unknown placeholder, a name ending in a directory separator, a name of only dots before the ending or a missing directory fails before the run, and so does an unreadable `-f` report; the names are fixed there, so a run across midnight writes where it was checked. All files are rendered and written to temporary files before any is put in place; if one cannot be put in place, the message names those already written. Removed: `--format`, `--out`, `--previous`, the command `verify`; JSON is no longer printed to the terminal (`Text::json` lost its ASCII mode). `-o`/`-f` are refused for `plan`, `apply`, `rollback` and `rules`; `--scan` is refused for `check`; `--extra-candidates` applies to `check`, `plan` and `apply`. Tests: `tests/options-test.php` (62 cases, including the names of `-o`/`-f`), `tests/windows-admin-test.ps1` and `tests/run-version-matrix.sh` read the JSON report through `-o`; `examples/generate.sh` writes the HTML reports with `-o` and the comparison as `05-compare.*`; `examples/output/` regenerated with this state. Reading the earlier report goes through `Fs::read` (one handle, regular file only, size by `fstat`, at most 50 MB) instead of checking and reading the path in separate steps. - **HTML run log of `apply` and `rollback` in the journal:** `apply --execute` writes `apply.html` next to `apply-log.json` — outcome (executed, with warnings, failed, aborted), tiles for findings before/after and the comparison, the planned changes with the state of each SQL statement from the journal, what was not done and why, the steps with time and status, the files touched with their backups, the comparison before/after (or why the re-check was impossible) and how to roll back. It is written in a `finally` once the journal exists, so a run that ends with an exception leaves it as well. `rollback` writes `rollback.html` (complete) or `rollback-attempt-