Repository navigation
Use prepared statements for Manticore queries in the web UI - #526
Merged
Merged
Conversation
- Bind all user and session supplied values in SphinxQL queries instead of interpolating them; this fixes SQL injection via the id: search term, extra_folders and the folder update request - Bind integers as PDO::PARAM_INT in the Sphinx driver, so they are not quoted in LIMIT and integer attribute comparisons - Fix can_download() and can_restore(): they passed 3 values for 2 placeholders, so the query always failed and the per-hour limits were never enforced - Keep the user part of the full-text query self-contained, so it can't escape the group AND-ed with the email address filter - Bump the Manticore image in docker-compose.yaml to 29.9.0 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The extra_folders request parameter was not checked against the folders the user may access. Apply the same rule as the folder picker: auditors may search any folder, other users only those in their session. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Rewrites every
$this->sphx->queryin the web UI to bind its values instead of interpolating them, and stops the full-text search expression from breaking out of the per-user address filter.SQL injection fixes
model/search/search.phpid:expert search term andextra_folderswere inserted raw intoid IN (...)/folder IN (...). They are now parsed to integers and bound. If no valid value is left, they match nothing.MATCH(?)),direction,size(operator checked against a strict pattern, number bound), the session folder list, tag/noteuidand search text, and all ID lookups are now bound. LIMIT and OFFSET are cast to integers.sphx_querysession variable.model/folder/folder.php: the folder update tookidandfolder_idstraight from POST. Both are now bound.model/search/message.php: tag and note lookups are bound.model/audit/audit.php:action,meta_idand the search text are bound.system/database/sphinx.php: integers are bound asPDO::PARAM_INT, so they aren't quoted in LIMIT or integer attribute comparisons.ATTR_EMULATE_PREPARESis now set explicitly.Bug fix
can_download()andcan_restore()passed 3 values for 2 placeholders, so the query always failed andMAX_DOWNLOAD_PER_HOUR/MAX_RESTORE_PER_HOURwere never enforced.Full-text search operator fix
For non-auditor users, the query is
( user search ) & <address filter>. A search such asx ) | ( ycould reorder that expression and get around the address filter. An unclosed quote or a\before a parenthesis could do the same. The newfixup_match_grouping()removes backslashes, takes parentheses out of quoted phrases, drops unmatched), and closes open quotes and parentheses before the query is wrapped.Folder restriction
extra_foldersfrom the request is now limited to the folders the user may access, using the same rule as the folder picker: auditors may search any folder, other users only the folders in their session.Other
docker/docker-compose.yamlbumped to 29.9.0.Test plan
php -lon the changed files (PHP 8.3)phpunit tests/EmailTest.php: 19 tests OK, including 10 newfixup_match_groupingcases. The full suite has 8ParseMessageTestfailures, and the same 8 fail onmaster.Sphinxdriver againstmanticoresearch/manticore:29.9.0: bound ints,MATCH(?),IN (?,?),size > ?, quotes in the search text, a sanitized breakout attempt (the address filter still applies) andUPDATE ... SET folder=?all work. A quoted int (uid='5') is rejected by Manticore 29.9, which confirms that thePARAM_INTbinding is needed.tests/run.sh) in CIid:,size:>1M,d:inbound,tag:,note:, folder restrictions, the audit search and CSV export, and the download limit🤖 Generated with Claude Code