Commit graph

1669 commits

Author SHA1 Message Date
Adam Warner
1f5960d71b
Merge branch 'development' into fix/debug-redact-secrets
Keep the tests of both sides in test/test_symlink_safety.bats.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Adam Warner <github@promofaux.dev>
2026-11-11 17:31:20 +00:00
Adam Warner
45a503fa45
Do not log the password hashes or the TOTP secret in the debug log
pihole -d logs /etc/pihole/pihole.toml through make_array_from_file,
which redacted nothing, so webserver.api.pwhash, app_pwhash and
totp_secret ended up in the debug log and in the tricorder upload
(GHSA-qfq3-88xg-765w). The only existing redaction (pwhash in
parse_file) is not used for this file.

Replace non-empty values of these keys with "<removed>". Empty values
are left as they are, so the log still shows whether one is set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Adam Warner <github@promofaux.dev>
2026-11-06 01:54:59 +00:00
Adam Warner
ef4a2f6352
Do not let pihole-controlled paths steer root in checkout and uninstall
/etc/pihole and pihole.toml are controlled by the pihole user
(GHSA-5w4v-f65m-323f):

- pihole checkout wrote /etc/pihole/ftlbranch as root and chmod-ed it,
  following a symlink planted there. Write it as the pihole user
  instead, removing whatever is at the path first.
- The uninstaller ran rm -rf on webserver.paths.webroot/webhome and
  rm -f on files.database, files.gravity and files.macvendor as root.
  Only remove the web interface directory if it is a checkout of the
  Pi-hole web repository, and delete the databases as the pihole user,
  before that user is removed. The defaults live in /etc/pihole, which
  is removed anyway.

The macvendor.db download in the installer, also part of this
advisory, is fixed together with GHSA-wp3p-45h3-2v82.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Adam Warner <github@promofaux.dev>
2026-11-06 01:54:59 +00:00
Adam Warner
e0cc934dd6
Do piholeDebug.sh's work in pihole-owned directories as the pihole user
/etc/pihole and /var/log/pihole are owned by the pihole user, who can
replace any file in them with a symlink. pihole -d runs as root and read
the logs and config files there with head/tail/sed, wrote the debug log
with a plain redirect and then chmod/chown-ed it by path, so a planted
symlink made root copy any file into the (pihole-readable) debug log, or
truncate, overwrite and re-own any file (GHSA-jvg9-fm8x-2jqq).

Do that work as the pihole user via setpriv instead, as
pihole-FTL-prestart.sh and updatecheck.sh already do:
- read files below those directories as that user
- query gravity.db and pihole-FTL.db as that user (their paths come
  from pihole.toml, and pihole-FTL runs as that user anyway)
- write the debug log as that user, removing whatever is at the path
  first, with mode 0640; the root chmod/chown is gone
- upload it to tricorder as that user

A symlink can then only lead to what the pihole user can already reach.
The debug log is now owned by pihole:pihole instead of root:pihole.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Adam Warner <github@promofaux.dev>
2026-11-06 01:16:28 +00:00
darkexplosiveqwx
fde089c6e9
use setpriv for dropping from root to pihole
Some checks failed
Check for merge conflicts / main (push) Has been cancelled
Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
2026-11-03 13:25:42 +01:00
Dominik
ef23f95259
Fix quiet flag propagation and complete logrotate output in piholeLogFlush (#6698)
Some checks failed
Check for merge conflicts / main (push) Has been cancelled
2026-10-27 20:43:44 +01:00
Chris Sommers
412f3a49e9
Fix quiet flag propagation and complete logrotate output in piholeLogFlush
Parse the quiet flag at the script level so flush_log() does not check a shadowed $* on manual flushes, and print the 'Rotated logs' completion line after logrotate in once mode.

Fixes #6289

Signed-off-by: Chris Sommers <chris.sommers@icloud.com>
2026-10-25 10:22:26 -07:00
Adam Warner
8170cfbbb6
Fix updatecheck.sh reporting null remote hashes when run from /root
Since the privilege drop was added to updatecheck.sh, the script re-runs
itself as the pihole user via `su`, which keeps the caller's working
directory. When started from cron the working directory is /root (mode
0700), which the pihole user cannot read. `git ls-remote` in
get_remote_hash() then fails repository discovery with "fatal: error
reading '/root/.git'", and GITHUB_CORE_HASH, GITHUB_WEB_HASH and
GITHUB_FTL_HASH are written as null.

Change to / at the start of the script so that both the root and the
re-executed pihole invocation start from a directory every user can read.

Fixes pi-hole/docker-pi-hole#2084

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2026-10-20 18:12:54 +01:00
Dominik
06b011bbf1
Flush the last 24 hours of queries through the FTL API (#6716) 2026-10-17 12:16:35 +02:00
Adam Warner
c8938a1580
Merge commit from fork
fix: don't let root write the version file into pihole-owned /etc/pihole
2026-10-17 11:14:30 +01:00
Adam Warner
9d96d1c941
Merge commit from fork
Never write to config-supplied paths as root
2026-10-17 11:12:00 +01:00
DL6ER
555dd4d8b3
Only accept a PID naming a running pihole-FTL
`/run/pihole-FTL.pid` is owned by the `pihole` user, but root reads it. `getFTLPID()` only rejected values starting with a non-digit, so `1+a[$(cmd)]` passed and was executed by the arithmetic `[[ ... -eq ... ]]` checks in `pihole`. The logrotate `postrotate` sent `kill -USR2` to whatever the file contained, including `-1`.

1. `getFTLPID()` accepts only a plain number whose `/proc/<pid>/comm` is `pihole-FTL`.
2. The logrotate `postrotate` uses `getFTLPID()`. The installer swaps this line in existing files, which are otherwise never replaced.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2026-10-17 11:17:39 +02:00
Adam Warner
e05dc3f139
fix: never run updatecheck.sh as root
updatecheck.sh writes the versions file into /etc/pihole, which is owned
by the unprivileged pihole user. When it ran as root (the installer,
`pihole -up`, `pihole checkout`, `sudo pihole updatechecker`, the Docker
start-up check, ...) the pihole user could watch the directory, swap the
script's temporary file for a symlink and have root chmod/chown/append
to whatever it pointed at. Reproduced: a root-only file ended up owned by
pihole.

- When started as root, hand over to the pihole user (`su`) and exit
  with its result. This covers every caller, including future ones, and
  the pihole user can only damage what it already owns. The "reboot"
  argument is forwarded.
- Drop the chown of the temporary file; it is no longer needed and was
  the dangerous part.
- Use `mv -fT` so that a symlink to a directory at the target path is
  replaced rather than having the temporary file moved into the
  directory.

Tests (fresh install): started as root the script must do its work as
the pihole user and write a pihole-owned 0644 versions file; a symlink
(to a file or to a directory) at the target path must be replaced rather
than followed.

Note: running as the pihole user needs git to trust the root-owned Core
and Web repositories (safe.directory). The installer sets that up (see
the following commit); other installers of this script, such as the
Docker image, need the equivalent.

Reported-by: Keith Linneman (LinnemanLabs)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2026-10-15 19:48:02 +01:00
Adam Warner
85de82dd2b
Address review feedback on GHSA-xch2-4qxw-g5vj fix
- updatecheck.sh: reword the publish comment to refer to mv/rename(2) and
  place it directly above the mv call; use chmod 0644
- pihole-FTL-prestart.sh: replace the loop/rm/no-op redirect with a single
  documented su call using touch and chmod

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2026-10-15 19:48:01 +01:00
Adam Warner
c1062f43b0
fix: don't let root write the version file into pihole-owned /etc/pihole
The `pihole updatechecker` cron job and pihole-FTL-prestart.sh both ran as
root and created/truncated/chmod-ed /etc/pihole/versions on a fixed path
without O_NOFOLLOW. Since the pihole user owns /etc/pihole, a compromised
pihole account could replace `versions` with a symlink to any root-owned
file and have root truncate it, relax its mode, or create it. The chmod
step also allows exposing e.g. /etc/shadow. See GHSA-xch2-4qxw-g5vj.

- pihole.cron: run `updatechecker` as the pihole user (like updateGravity),
  so root no longer writes into /etc/pihole from cron.
- updatecheck.sh: build the file in a mktemp'd temp file and rename() it
  into place; a symlink at the target is replaced, not followed.
- pihole-FTL-prestart.sh: create/permission `versions` (and, same bug
  class, `dhcp.leases`) as the pihole user via `su`, neutralising any
  planted symlink. A symlink to a root-owned file then only yields EPERM.
- basic-install.sh / uninstall.sh: register the root-owned Core and Web
  repos in git's system-wide safe.directory list so the now-unprivileged
  updatechecker can still read local versions.

Behaviour change: /etc/pihole/versions is now consistently mode 0644 after
a service (re)start; the find in prestart previously left it 0640, against
the file's own comment and updatecheck.sh's own chmod 644.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2026-10-15 19:47:57 +01:00
DL6ER
e60c0bafcf
Flush the last 24 hours of queries through the FTL API
`pihole -f` stopped FTL with `service` to delete the last 24 hours from the database. Docker has no `service` command, so nothing was deleted there and the queries stayed in memory. `POST /api/action/flush/logs` does the same inside FTL while it keeps running: it truncates `pihole.log`, drops the queries from memory and deletes them from the database.

`PI_HOLE_SCRIPT_DIR` is no longer `readonly`, as `api.sh` sets it as well.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2026-10-11 16:27:55 +02:00
DL6ER
406c6bc012
Never write to config-supplied paths as root
`files.gravity` and the `files.log.*` paths come from `pihole.toml`, which the `pihole` user owns. A root `pihole -g` used them for `chown`, `mv` and database creation, and a root `pihole flush` truncated and `chmod`ed them, so the `pihole` user could take over any directory or clobber any file.

1. `gravity.sh` now re-executes itself as `pihole` when started as root. The weekly cron, the web interface and the installer already run it that way. `/etc/pihole` is handed to `pihole` first, as Docker runs gravity before the FTL prestart script does so.
2. `piholeLogFlush.sh` writes the log files as `pihole`. The rest of the manual flush still needs root to stop FTL.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2026-10-11 10:32:42 +02:00
DL6ER
0d3ac3644d
Migrate existing databases to schema version 21
The template is only used for a database created from scratch, so without a
migration step the indexes, the `WITHOUT ROWID` tables and the corrected update
triggers would reach new installations only.

`20_to_21.sql` rebuilds the three junction tables and `info` through a
temporary table - an `ALTER TABLE ... RENAME` would reparse the schema while
the views still point at the table being replaced - adds the two group indexes
and replaces the triggers that matched by content. The result has the same
schema as a database created from the template.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2026-09-19 16:17:03 +02:00
Adam Warner
340b37ab51
Stop double-rotating logs now that pihole is in /etc/logrotate.d
Our config moved into /etc/logrotate.d/pihole a while back, so the
system's own scheduled logrotate now picks it up too. Our nightly and
@reboot forced runs were still using a private state file though, so
the system's run and ours each rotated the same logs independently,
unaware of each other.

Drop the private state file and use logrotate's default one instead,
so both sides agree on what's already been rotated. Also clean up the
now-stale /etc/pihole/logrotate and private state file left behind by
older installs.

Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2026-07-07 13:40:38 +01:00
Christian König
88b47a280a
Use /etc/logrotate.d/pihole for logrotate file instead of /etc/pihole/logrotate
Signed-off-by: Christian König <github@yubiuser.dev>
2026-05-13 08:38:31 +02:00
Adam Warner
b4af3f3ead
We can also hardcode the PID file location in utils.sh
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2026-04-25 10:51:55 +01:00
Adam Warner
b065830df0
Merge commit from fork
hardcode PID file path in service hooks
2026-04-24 22:10:31 +01:00
darkexplosiveqwx
c65b63b10b
Merge branch 'development' into logrotate
Conflicts resolved: automated install/basic-install.sh

Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
2026-04-20 17:15:49 +02:00
Adam Warner
a3ed471d05
security: hardcode PID file path in service hooks
The pihole-FTL-prestart.sh and pihole-FTL-poststop.sh scripts are
executed as root by systemd (via the '+' prefix). Both previously read
the PID file path from pihole.toml via getFTLConfigValue — a file the
pihole user can write to directly. An attacker with pihole-user access
could set files.pid to an arbitrary path and trigger a service restart
to cause root to delete then recreate any file on the system, enabling
local privilege escalation.

Fix by inlining the hardcoded path /run/pihole-FTL.pid directly in
each hook, removing any dependency on user-controlled config. The same
hardening is applied to the SysV init script for consistency.

See: GHSA-6w8x-p785-6pm4

Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2026-04-19 16:42:58 +01:00
yubiuser
dca5d882f6
Apply suggestions from code review
Co-authored-by: Adam Warner <github@adamwarner.co.uk>
Signed-off-by: yubiuser <github@yubiuser.dev>
2026-04-17 17:13:01 +02:00
Christian König
ed3b6cb776
Set versions in /etc/pihole/versions to null if script fails
Signed-off-by: Christian König <github@yubiuser.dev>
2026-04-17 17:13:01 +02:00
darkexplosiveqwx
1c7154d5da
fix comment
Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
2026-04-10 20:49:58 +02:00
darkexplosiveqwx
f88e3e2893
Remove reference to /usr/local/bin/COL_TABLE
This was most likely added accidentally (during a refactor in 2017)
Both the 2017 and current version use /opt/pihole/COL_TABLE, as defined earlier and sourced earlier in the code.
Remove PIHOLE_COLTABLE_FILE from REQUIRED_FILES since /usr/local/bin as well as /opt/pihole are never checked

Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
2026-04-10 20:49:54 +02:00
Adam Warner
1cb17cdcf9
Wipe version file before creating a new one (#6538) 2026-04-03 23:15:33 +01:00
Adam Warner
3c3952a60e
Merge commit from fork
Refactor version loading to enhance security and prevent shell injection
2026-04-03 16:53:17 +01:00
Adam Warner
2aa38f4fd7
Return 0 instead of 1 to make compatibile with set -e
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2026-03-24 18:43:32 +00:00
Christian König
2f8fa724f2
Prevent exiting due to set -e
Signed-off-by: Christian König <github@yubiuser.dev>
2026-03-22 10:01:11 +01:00
Christian König
300cdb71b8
Fix return status capture of FTL check_download exists
Signed-off-by: Christian König <github@yubiuser.dev>
2026-03-22 09:49:54 +01:00
Adam Warner
e001c87479
Refactor version loading to enhance security and prevent shell injection
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2026-03-18 21:41:36 +00:00
RD WebDesign
36601eef3a
Remove readonly from piholeNetworkFlush.sh to avoid error message
This is a quick fix to avoid the error when api.sh tries to set the
variable again.

Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
2026-03-01 17:29:19 -03:00
Christian König
f28233729c
Remove additional ':' from debug log system time output
Signed-off-by: Christian König <github@yubiuser.dev>
2026-02-24 08:51:07 +01:00
Christian König
4125bcccdc
Files should be created before calling addOrEditKeyValPair
Signed-off-by: Christian König <github@yubiuser.dev>
2026-02-18 09:25:10 +01:00
Christian König
ac37014628
Truncate version file instead of removing and creating freshly
Signed-off-by: Christian König <github@yubiuser.dev>
2026-02-18 09:22:11 +01:00
Christian König
d765ce768f
Wipe version file before creating a new one
Signed-off-by: yubiuser <github@yubiuser.dev>
2026-02-16 20:11:17 +01:00
darkexplosiveqwx
32b37668cf
add logrotate to DEB and RPM dependencies
Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
2026-01-29 21:22:50 +01:00
Dan Schaper
7442623f2f
Debug log - Add colors to gravity tables (#6485) 2025-12-04 12:52:07 -07:00
RD WebDesign
1f4ed9b518
Replace some strings with their colored equivalents
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
2025-11-30 18:43:40 -03:00
RD WebDesign
95ae51bbdb
Use more specific strings on the tables to match only desired text
- use `--no---` and `--yes---` to make sure the strings won't match user
comments or parts of domains
- also use `-ALLOW-` and `-BLOCK-`

Also reduce the domain column to 90 characters

Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
2025-11-30 18:42:02 -03:00
RD WebDesign
247b0c506b
Remove custom FTL FirewallD zone checks from debug log
Removed checks for custom FTL FirewallD zone in piholeDebug.sh.

Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
2025-11-26 23:46:43 -03:00
Adam Warner
d4db2dca22
Improve gravity tables presentation on the debug log (#6460) 2025-11-25 18:59:04 +00:00
RD WebDesign
8c6bb3f8da
Use text colums instead of number codes on gravity tables
- Domains table ("type" column): replace 0, 1, 2 and 3 with
  "exact-allow", "exact-deny", "regex-allow" and "regex-deny"
- All tables: use yes/no for "enabled" columns

Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
2025-11-20 16:46:38 -03:00
RD WebDesign
987a59f7e5
Show "Block" and "Allow" instead of 0 and 1
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
2025-11-19 16:35:39 -03:00
darkexplosiveqwx
1dc8bfc950
Use port from dns.port in piholeDebug.sh
Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
2025-11-16 16:35:05 +01:00
Rob Gill
bf41c3dded
debug - speed up processing and display of file contents and services
Use bash-internal globs and parameter expasion in preference to
assignment from output of ls or basename per file/directory.

When displaying file contents, call sed once and preprocesses the entire
file (eg pihole.toml), rather than spawning a new sed process for every
line of the file.

When checking services, call awk once to extract all data for each ip:port
pair, rather than three times.

Signed-off-by: Rob Gill <rrobgill@protonmail.com>
2025-11-10 14:33:07 +10:00
RD WebDesign
40aa986af1
Add list "type" (block/allow) to the debug log table
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
2025-11-03 17:39:36 -03:00