T09 · Insecure Skill Coding Practices
- Location
phase4/query_engine.py:42- Finding
SPARQL Injection Through Unsafe Template Substitution
- Content
View full analysis
str: """Render the template with parameter values.""" result = self.sparql_template for param in self.parameters: if param in kwargs: result = result.replace(f"${{{param}}}", str(kwargs[param])) return result ``` Example vulnerable template: ```python QueryTemplate( name="find_entity_by_name", description="Find entities by name (partial match)", sparql_template=""" PREFIX rdfs: PREFIX rdf: PREFIX dk-class: SELECT ?entity ?type ?name ?description WHERE { ?entity rdf:type ?type . ?entity rdfs:label ?name . OPTIONAL { ?entity rdfs:comment ?description } FILTER(CONTAINS(LCASE(?name), LCASE("${name}"))) } LIMIT ${limit} """, parameters=["name", "limit"], category="entity", ) ``` Execution sink: ```python def execute(self, sparql: str) -> QueryResult: start = time.time() self._query_count += 1 try: results = self.graph.query(sparql) elapsed = (time.time() - start) * 1000 self._total_time_ms += elapsed bindings = [] if results.vars: var_names = [str(v) for v in results.vars] ...[truncated 3024 chars]- Remediation
View remediation
