Skip to content

fix: validate node name components before SPARQL substitution#113

Open
SoundMatt wants to merge 1 commit into
COVESA:mainfrom
SoundMatt:fix/sparql-injection-guard
Open

fix: validate node name components before SPARQL substitution#113
SoundMatt wants to merge 1 commit into
COVESA:mainfrom
SoundMatt:fix/sparql-injection-guard

Conversation

@SoundMatt
Copy link
Copy Markdown

Problem

Node name components derived from incoming WebSocket messages are substituted directly into SPARQL query templates via replaceAllQueryVariables without any sanitisation. A malicious or MITM WebSocket server can craft a node name containing SPARQL metacharacters to inject arbitrary query logic.

Root cause

extractObjectsAndDataElements splits the raw node name on . and returns the parts as plain strings. These parts are then used as-is to replace %A% and %B% placeholders in query templates. There is no check that the components are valid identifiers before substitution.

Fix

After extractObjectsAndDataElements returns, validate every component (both object elements and the data element) against the pattern [A-Za-z][A-Za-z0-9_]*. If any component fails the check, throw std::runtime_error before any query substitution occurs. Add <regex> to the include list.

Node name components from WebSocket messages were substituted directly
into SPARQL query templates via replaceAllQueryVariables without any
validation, allowing a malicious or MITM WebSocket server to inject
arbitrary SPARQL. Add a regex guard that rejects any component not
matching [A-Za-z][A-Za-z0-9_]* with a runtime_error.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>
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.

1 participant