Fixed security risk: prevent SPARQL injection attacks#28
Fixed security risk: prevent SPARQL injection attacks#28justjjosh wants to merge 2 commits intoeclipse-thingweb:mainfrom
Conversation
- Add sanitize_sparql_uri() function to escape and validate URI parameters - Add sanitize_sparql_string() function to escape string literals - Add query validation to /search/sparql endpoint (read-only only) - Update all URI parameters in SPARQL queries to use sanitization - Add ValueError error handler to return proper HTTP 400 responses - Create comprehensive test suite with 30+ injection attack tests Fixes CWE-89 SQL Injection vulnerabilities: - Direct SPARQL query execution (/search/sparql endpoints) - URI parameter injection in query templates All sanitization follows SPARQL 1.1 W3C specification for proper escaping and validation. Test Results: 30/30 tests passing
|
@justjjosh - thanks for tackling this important issue. I let Co-Pilot run over it and got several change requests that you also can find at: https://github.com/eclipse-thingweb/domus-tdd-api/tree/fix/sparql-injection Please check whether these make sense. 🔴 Critical — Breaks all normal Thing operations1.
|
|
Hi @wiresio, Thank you (and Copilot) for this incredibly thorough and precise review! The feedback is completely spot-on, especially regarding the double angle brackets and the PREFIX stripping logic. You might have noticed I just pushed a quick commit to address Point 2 (adding the < character to the regex), but I see it tripped the automated linting/formatting pipeline. Rather than pushing piece-meal, I am going to consolidate all 9 of these fixes locally, run the formatting tools (black / flake8), and push a single, clean update. Thanks again for the feedback! |
Fixes CWE-89 SQL Injection vulnerabilities:
All sanitization follows SPARQL 1.1 W3C specification for proper escaping and validation.
Test Results: 30/30 tests passing