Fix critical SQL injection vulnerabilities #160
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Vulnerability
When installing PoracleWeb yesterday I noticed some unexpected PHP debugging output in my web browser, which led to me inspecting part of the source code. While skimming, I noticed numerous unsafe SQL queries, and drafted a quick proof-of-concept to verify that various public pages were vulnerable to unauthenticated SQL injection attacks. I shared the proof of concept code with @bbdoc and one additional user of PoracleWeb in order to validate my findings, but prefer to not share it here since it is a CVE 9.8 vulnerability, capable of being exploited by anonymous users on the internet, and until a remediation is readily available I feel it would cause more harm to point to exactly which codepaths are publicly vulnerable.
Changes in this PR
This PR replaces all dynamic calls to
query($sql)with PreparedStatement calls. In several instances there are dynamic components not able to be guarded by PreparedStatement sanitation, which have had additional guards placed on them to verify integrity of the data before composing the SQL query.AI Disclosure:
I used Claude Code from Anthropic both in the initial triaging of this vulnerability, as well as drafting the patch. Throughout the process I individually reviewed each small change before approving them, often tweaking or re-drafting the result to be more optimal. I have built PHP software in the past professionally, and I have both caused (when much younger) and resolved SQL injection vulnerabilities in my professional career pre-AI, and I am confident in my ability to judge quality output. Everything Claude contributed I could've easily written myself, just would've taken several times as long. Here is the entire chat transcript for the diagnosis and resolution of this issue.
Next steps
I do not have a fully functional instance of PoracleWeb that I can test this change against. Because of this, I'd appreciate any help testing and verifying this fix, both for functionality purposes (make sure I didn't break anything) and security purposes (verify the vulnerability is resolved). I've published my changes as a docker image at ghcr.io/complementarypogo/poracleweb:a0b8b92db463647b06bc7a104a4c818aa46ff9fe. I can be reached here in the comments of this PR, or on discord
@compl3m3nt.π΄ In the meantime I would advise existing operators of PoracleWeb to immediately discontinue use of it until a remediation is available and confirmed, and check your databases and server hosts for signs of tampering or persistent access.