[critical] fix: [wiki] escape SPARQL literal built from user text - #869
Open
elhoim wants to merge 1 commit into
Open
[critical] fix: [wiki] escape SPARQL literal built from user text#869elhoim wants to merge 1 commit into
elhoim wants to merge 1 commit into
Conversation
The Wikidata Lookup module builds a SPARQL query by concatenating the attacker-controlled `text` attribute directly into a quoted RDF literal. A value containing a double quote breaks out of the literal and lets an analyst-supplied attribute value inject arbitrary SPARQL into the query sent to Wikidata's public endpoint, changing what is matched or causing a malformed query the module reports as an opaque "wikidata API not accessible" error instead of the real cause. Escape backslashes and double quotes in the text before interpolating it into the literal, matching the escaping SPARQL string literals require. Verified with flake8 (clean) and the full pytest suite against a local modules server on port 6760: 161 passed, 4 skipped, 5 subtests passed, matching the documented baseline. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018dfYpyaSZd1nxSRLr8suj8
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.
BLUF —
wiki.pyinterpolates untrusted text into a SPARQL literal unescaped, allowing query injection.misp_modules/modules/expansion/wiki.pybuilds its SPARQL query by concatenating the untrustedtextattribute into a quoted literal, andSPARQLWrapperdoes not escape it, so a value containing a double quote or backslash injects arbitrary SPARQL into the query sent to Wikidata.The defect
misp_modules/modules/expansion/wiki.pybuilt its SPARQL query by string-concatenating the untrustedtextattribute directly into a quoted literal:SPARQLWrapperdoes not escape values interpolated into a manually built query string. Anytextvalue containing a double quote (or backslash) breaks out of the string literal, letting an attacker-controlled attribute inject arbitrary SPARQL into the query sent to Wikidata's public endpoint.Impact
The
wikiexpansion module is typically run against attribute values pulled from event data, which may originate from external/untrusted sources (e.g. shared events, automated feeds). A craftedtextvalue can manipulate the SPARQL query executed on behalf of the analyst, altering or corrupting the enrichment results returned into the MISP event. The endpoint is read-only and public, so this is query manipulation / false enrichment output, not data exfiltration or compromise of the endpoint itself.The fix
Escape backslashes and double quotes in
textbefore interpolating it into the query string literal, following standard SPARQL literal escaping rules. Text with no special characters produces an identical query to before, so there is no behaviour change for the common case.Verification
.venv/bin/python -m py_compile misp_modules/modules/expansion/wiki.py— compiles cleanly.Found during a review of the repository; other findings are being submitted as separate PRs.
🤖 Generated with Claude Code