Skip to content

harden: the database cleanup script constructs sql quer... in... - #6681

Open
anupamme wants to merge 1 commit into
pi-hole:developmentfrom
anupamme:fix-repo-pi-hole-v-001-advanced-scripts-piholelogflush-sh
Open

anupamme wants to merge 1 commit into
pi-hole:developmentfrom
anupamme:fix-repo-pi-hole-v-001-advanced-scripts-piholelogflush-sh

Conversation

@anupamme

@anupamme anupamme commented Aug 9, 2026

Copy link
Copy Markdown

Summary

Harden input handling in advanced/Scripts/piholeLogFlush.sh (flagged by multi_agent_ai).

Vulnerability

Field Value
ID V-001
Severity MEDIUM
Scanner multi_agent_ai
Rule V-001
File advanced/Scripts/piholeLogFlush.sh:84
Assessment Defensive hardening

Description: It is a defence in depth/ path validation. No vulnerability is found/reported in this PR.

Changes

  • advanced/Scripts/piholeLogFlush.sh

Behaviour Preservation

The change is scoped to 1 file on the vulnerable path; it only tightens handling of untrusted input and leaves valid inputs unaffected.


This patch removes an exploit primitive — a code pattern that, while not independently exploitable today, could be chained with other weaknesses by automated exploit-development tooling. Proactive removal of such primitives raises the bar against increasingly capable automated attack tools.


Automated security fix by OrbisAI Security

@anupamme
anupamme requested a review from a team as a code owner August 9, 2026 13:03
@yubiuser

yubiuser commented Aug 9, 2026

Copy link
Copy Markdown
Member

Please explain in more detail why do you think it was possible to

inject malicious SQL commands to delete, modify, or exfiltrate data from the Pi-hole FTL database

and now your change would prevent this.

@anupamme

anupamme commented Aug 9, 2026

Copy link
Copy Markdown
Author

Thanks for calling this out. On re-review, I agree that my original description overstated the issue.

DBFILE is passed as a separate argument to pihole-FTL sqlite3; it is not interpolated into the SQL statement. The SQL itself is static, so this is not SQL injection, and the claim that an attacker could inject arbitrary SQL commands was incorrect.

The security-relevant part of the change is the argument boundary:

pihole-FTL sqlite3 -ni -- "${DBFILE}" ...

The -- ensures that a configured database path beginning with - cannot be interpreted as a sqlite3 option. The path validation additionally restricts DBFILE to the expected filesystem-path character set.

I’ll update the PR description to remove the SQL-injection/CRITICAL claim and describe this as defensive argument/path validation instead. I’ll also move the validation before the log flushing so an invalid configuration fails before making any changes.

If the project doesn’t consider this hardening necessary given how files.database is controlled, I’m happy to close the PR.

@anupamme
anupamme force-pushed the fix-repo-pi-hole-v-001-advanced-scripts-piholelogflush-sh branch from 1d4e45b to 95f7786 Compare August 9, 2026 13:32
@yubiuser

yubiuser commented Aug 9, 2026

Copy link
Copy Markdown
Member

The commit needs to be signed-off to pass DCO test

…eLogFlush.sh

DBFILE is sourced from FTL configuration (files.database) and passed as a
positional argument to pihole-FTL sqlite3. The SQL statement is static; this
is not SQL injection. The hardening addresses two separate concerns:

- `--` prevents a database path beginning with `-` from being misinterpreted
  as a sqlite3 option (argument injection / option smuggling).
- The allowlist regex restricts DBFILE to expected filesystem-path characters,
  rejecting values that fall outside the normal configuration range.

The validation is now performed before any log files are flushed so that an
invalid configuration fails cleanly without partial side effects.

Signed-off-by: anupamme <mediratta@gmail.com>
@anupamme
anupamme force-pushed the fix-repo-pi-hole-v-001-advanced-scripts-piholelogflush-sh branch from 95f7786 to ef3a9b7 Compare August 9, 2026 15:35
@anupamme

anupamme commented Aug 9, 2026

Copy link
Copy Markdown
Author

The commit needs to be signed-off to pass DCO test

done.

@rdwebdesign

Copy link
Copy Markdown
Member

@anupamme

Note:

Like said here https://github.com/pi-hole/pi-hole/security/policy, please do not open an ISSUE to report a security problem.

Next time, if you think you found a security vulnerability, please report it privately using the "Security and quality" tab above, or send an email to disclosure@pi-hole.net.

@anupamme

Copy link
Copy Markdown
Author

Ack.

@yubiuser

Copy link
Copy Markdown
Member

If you would not have removed the PR template but instead read it, you would have known that all PRs should be based on and target development branch.

@anupamme
anupamme changed the base branch from master to development August 22, 2026 01:51
@anupamme

Copy link
Copy Markdown
Author

If you would not have removed the PR template but instead read it, you would have known that all PRs should be based on and target development branch.

done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants