Repository navigation
fix(security): avoid blocked keyword false positives in SQL literals and comments - #242
Open
tuoluzhe8521 wants to merge 1 commit into
Open
tuoluzhe8521 wants to merge 1 commit into
tuoluzhe8521 wants to merge 1 commit into
Conversation
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.
A valid read-only query such as
SELECT 'ios_created_time_parse_failure' AS metricis rejected asCREATEbecause the keyword blocklist searches for substrings inside literal and comment tokens. Ordinary comments such asSELECT 1 /* CREATE TABLE example */fail for the same reason.This change matches actual SQL keyword tokens instead of inspecting non-executable token contents. It preserves configured compound keywords, recognizes
CREATE OR REPLACE, and retains statement-leading commands such asKILLandSHUTDOWNwhen sqlparse classifies them as names. Reported blocked operations are deduplicated and sorted.Regression tests cover literals, ordinary comments, quoted identifiers, CTEs, real blocked operations, and configured compound keywords. Existing injection checks, the canonical read-only guard, error codes, and query complexity limits are unchanged.
Validation (Python 3.12, frozen development environment):
uv run pytest -q -W error: 1880 passed, 85 skipped; 68.13% coverage.uv run ruff check .,uv run mypy doris_mcp_server, and Bandit source scan passed.