Skip to content

Potential SPARQL injection: unsanitized user input interpolated into SPARQL queries #123

Description

@tanodev0

Summary

Several SPARQL query builders interpolate values that originate from HTTP request path parameters directly into SPARQL query strings via JS template literals, without escaping or validation. This looks like a security-sensitive bug, so I'm deliberately not including exploit payloads or a working proof-of-concept in this public issue.

Where

  • serverless/src/shared/getSkosConcept.js — the shortName and altLabel branches pass request-derived values straight through to the query builders below, unescaped.
  • serverless/src/shared/operations/queries/getTriplesForShortNameQuery.js
  • serverless/src/shared/operations/queries/getTriplesForAltLabelQuery.js
  • serverless/src/shared/operations/queries/getConceptsQuery.js
  • serverless/src/shared/operations/queries/getTotalCountQuery.js

These values ultimately come from event.pathParameters in serverless/src/getConcept/handler.js and serverless/src/getConcepts/handler.js (e.g. shortName, altLabel, pattern, conceptScheme), decoded but not sanitized before being embedded inside FILTER(... = LCASE("${value}"))-style string literals.

Why this stands out

The codebase already has serverless/src/shared/escapeSparqlString.js, which is applied to the fullPath branch in getSkosConcept.js (see lines around 162 and 177) — but it is not applied to the shortName/altLabel branches a few lines above, nor to the pattern/conceptScheme values used in getConceptsQuery.js / getTotalCountQuery.js. That inconsistency suggests the escaping requirement was already understood for one code path but missed for the others.

Suggested fix

Apply the existing escapeSparqlString() helper (or equivalent validation, e.g. allowlisting scheme names) consistently to every value interpolated into a SPARQL string literal across these files, not just the fullPath path.

Note

I'd be glad to share a full write-up, including a concrete input that demonstrates the issue, through a private channel — happy to use whatever vulnerability disclosure process NASA prefers (e.g. https://hackerone.com/nasa or https://www.nasa.gov/vulnerability-disclosure-policy/) if that's easier for the team to track.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions