Spring Cloud Gateway — 1 vulnerability check

noctis ships 1 vulnerability check for Spring Cloud Gateway, covering 1 CVE; each one has to observe the bug on the live service before it reports a finding.

← All products · Feeds on GitHub

Spring Cloud Gateway Actuator SpEL Injection

CVECVE-2022-22947
Severitycritical · CVSS 10.0
Categoryrce — Remote code execution
Serviceshttp, https
Detectionscript, http_request, set_var, match · highest QoD 75
Feedtests/vulnerabilities/spring-cloud-gateway/CVE-2022-22947.yaml

Detects VMware Spring Cloud Gateway instances vulnerable to SpEL code injection through the Gateway Actuator. A route whose filter value is the SpEL expression #{T(java.lang.Math).multiplyExact(a, b)}, with random per-run operands, is added and the routes refreshed. A vulnerable Gateway resolves the Java type reference, calls the static method and reflects the product a*b in the applied route, proving unrestricted SpEL evaluation, the RCE sink (QoD 75). Fixed releases reject type references and never reflect it; plain arithmetic is not used because fixed releases still evaluate it. Only a multiplication is called, no command is run. The injected route is deleted and the routes refreshed again.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. HTTP(S) request POST /actuator/gateway/routes/{{calc.rid}} with a crafted body
  3. HTTP(S) request POST /actuator/gateway/refresh
  4. HTTP(S) request GET /actuator/gateway/routes/{{calc.rid}}
  5. Parses / computes the next value with a Rhai script
  6. Checks verdict for NOCTIS_SPEL_TYPEREF_EVALUATED → finding QoD 75: Spring Cloud Gateway Actuator SpEL Injection (CVE-2022-22947)
  7. HTTP(S) request DELETE /actuator/gateway/routes/{{calc.rid}}
  8. HTTP(S) request POST /actuator/gateway/refresh

References:

Feed source — tests/vulnerabilities/spring-cloud-gateway/CVE-2022-22947.yaml
# VMware Spring Cloud Gateway — SpEL code injection via the Actuator (CVE-2022-22947)
#
# When the Gateway Actuator endpoint is enabled and exposed, an unauthenticated
# attacker can POST a new route whose filter carries a SpEL expression (#{...}).
# A follow-up POST /actuator/gateway/refresh makes the Gateway *evaluate* that
# expression while (re)building the route, so GET /actuator/gateway/routes/<id>
# reflects the computed result back. The original exploit abuses this to run
# `T(java.lang.Runtime).getRuntime().exec(...)` for RCE.
#
# Affected: Spring Cloud Gateway 3.1.0, <= 3.0.6 and older.
#
# DETECTION — benign SpEL type-reference differential (QoD 75), NOT exploitation:
#   noctis adds a route whose AddResponseHeader filter value is
#   #{ T(java.lang.Math).multiplyExact(<a>, <b>) } with random operands generated
#   fresh per run, refreshes, then reads the applied route back. A vulnerable
#   Gateway (StandardEvaluationContext) resolves the type reference, calls the
#   static method and reflects the product a*b; this is the same primitive the
#   public exploit uses with T(java.lang.Runtime). The fix (3.1.1 / 3.0.7) swaps
#   in a SimpleEvaluationContext that still evaluates plain arithmetic but
#   rejects type references, so the refresh fails ("EL1005E: Type cannot be
#   found 'java.lang.Math'"), the previous route cache is kept and the route
#   404s. A bare #{a*b} is NOT used: a fixed 3.1.1 evaluates it too and
#   reflects the product (verified on a real 3.1.1, #2470). Operands stay
#   <= 46337 so the product fits in a Java int (multiplyExact throws past it).
#   The route noctis created is deleted and the Gateway refreshed again as
#   cleanup (on a fixed Gateway this also clears the failing definition, so
#   later refreshes succeed again). The probe route only matches the random
#   path /<rid>-noctis-probe and has the lowest priority, so it never captures
#   real traffic while it exists. On a fixed Gateway, route changes made by
#   others during the few seconds of the probe only apply after the cleanup
#   refresh; if the cleanup DELETE fails, refreshes keep failing until the
#   route /actuator/gateway/routes/<rid> is removed.
#   Known gap: Gateway <= 2.1.x is vulnerable but its AddResponseHeader filter
#   has no toString, so the product is never reflected (no finding there).
uid: 01bd642e-f142-4793-8400-597fdfc8a9bc
name: "Spring Cloud Gateway Actuator SpEL Injection (CVE-2022-22947)"
description: |
  Detects VMware Spring Cloud Gateway instances vulnerable to SpEL code
  injection through the Gateway Actuator. A route whose filter value is the
  SpEL expression #{T(java.lang.Math).multiplyExact(a, b)}, with random
  per-run operands, is added and the routes refreshed. A vulnerable Gateway
  resolves the Java type reference, calls the static method and reflects the
  product a*b in the applied route, proving unrestricted SpEL evaluation, the
  RCE sink (QoD 75). Fixed releases reject type references and never reflect
  it; plain arithmetic is not used because fixed releases still evaluate it.
  Only a multiplication is called, no command is run. The injected route is
  deleted and the routes refreshed again.
cves: [CVE-2022-22947]
cvss: 10.0
severity: critical
confidence_base: 0.25
tags: [vmware, spring, spring-cloud-gateway, spel, actuator, rce, kev]
category: rce
services: [http, https]
author: noctis
version: "1.1.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2022-22947"
  - "https://tanzu.vmware.com/security/cve-2022-22947"
  - "https://spring.io/blog/2022/03/01/spring-cloud-gateway-cve-reports-published"

steps:
  # 1 — Generate two large random operands and the expected product + a random
  #     route id. The product is the value we later look for in the reflected
  #     route; 5-digit operands make the 9–10 digit product effectively
  #     impossible to collide with unrelated response text. SpEL evaluates
  #     integer literals as Java int (32-bit): both operands stay <= 46337 so
  #     the product never exceeds 2^31-1 — larger operands wrap around on a
  #     real Gateway and the exact product would never match (#2462).
  - id: calc
    action: script
    code: |
      let a = rand_int(10007, 46337);
      let b = rand_int(10007, 46337);
      #{ a: a.to_string(), b: b.to_string(), product: (a * b).to_string(), rid: "noctis" + rand_hex(6) }
    store_as: calc

  # 2 — Add a route whose AddResponseHeader filter value calls a static method
  #     through a SpEL type reference T(...), which only the vulnerable
  #     StandardEvaluationContext resolves.
  - id: add-route
    action: http_request
    method: POST
    path: "/actuator/gateway/routes/{{calc.rid}}"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    headers:
      Content-Type: "application/json"
    body: '{"id":"{{calc.rid}}","filters":[{"name":"AddResponseHeader","args":{"name":"X-Noctis-Result","value":"#{ T(java.lang.Math).multiplyExact({{calc.a}}, {{calc.b}}) }"}}],"predicates":[{"name":"Path","args":{"_genkey_0":"/{{calc.rid}}-noctis-probe"}}],"uri":"http://noctis.invalid","order":2147483647}'
    store_as: add_resp

  # 3 — Refresh so the Gateway (re)builds the route and evaluates the filter value.
  - id: refresh
    action: http_request
    method: POST
    path: "/actuator/gateway/refresh"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: refresh_resp

  # 4 — Read the applied route back. A vulnerable Gateway reflects the computed
  #     product; on a fixed one the refresh failed, so the route 404s.
  - id: read-route
    action: http_request
    method: GET
    path: "/actuator/gateway/routes/{{calc.rid}}"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: read_resp

  # Init the verdict so a non-connecting host leaves a safe default.
  - id: init-verdict
    action: set_var
    var_name: verdict
    var_value: "none"

  # 5 — Verdict is driven by OUR computed product: emit a fixed marker only when
  #     the reflected route contains the product a*b we calculated this run.
  - id: evaluate
    action: script
    condition: "read_resp.status != 0"
    code: |
      let body = read_resp.body;
      if stridx(body, calc.product) >= 0 { "NOCTIS_SPEL_TYPEREF_EVALUATED" } else { "none" }
    store_as: verdict

  # 6 — A match on the marker means the SpEL type reference was evaluated server-side.
  - id: confirm
    action: match
    source: verdict
    pattern: "NOCTIS_SPEL_TYPEREF_EVALUATED"
    on_match:
      finding:
        title: "Spring Cloud Gateway Actuator SpEL Injection (CVE-2022-22947)"
        description: "The Spring Cloud Gateway Actuator evaluated a SpEL type reference supplied in a route filter (a static Java method call), which fixed releases reject. This is the code-injection sink (RCE). Detection called only java.lang.Math.multiplyExact."
        remediation: "Upgrade Spring Cloud Gateway to >= 3.1.1 / >= 3.0.7. If the Actuator is not needed, disable it (management.endpoint.gateway.enabled=false) and never expose /actuator unauthenticated."
        confidence_delta: 0.50   # 0.25 + 0.50 = 0.75
        qod: 75
        evidence: "Gateway evaluated #{ T(java.lang.Math).multiplyExact({{calc.a}}, {{calc.b}}) } and reflected the product {{calc.product}} in the applied route: {{read_resp.body}}"

  # 7 — Cleanup: delete the route we created and refresh again. Best-effort.
  - id: cleanup-delete
    action: http_request
    method: DELETE
    path: "/actuator/gateway/routes/{{calc.rid}}"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: delete_resp

  - id: cleanup-refresh
    action: http_request
    method: POST
    path: "/actuator/gateway/refresh"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: cleanup_refresh_resp

View these feeds on GitHub