Skip to content
Access control Disclosed report Intermediate

Spring security configuration allows agent sessions to be hijacked

The Spring Security configuration left a thread-local security context set after an agent authenticated, so unauthenticated requests to certain endpoints could randomly be treated as authenticated. An attacker without credentials could read or upload artifacts, and combined with another issue, achieve stored XSS.

4cad Follow

Originally disclosed on HackerOne

  • Fixed in 9 days
  • Disclosed after 13 months

Summary

If agents have successfully logged in, then unauthenticated requests to /go/agent-websocket or /go/remoting/* will randomly succeed sometimes.

Description

The deprecated X509ProcessingFilter apparently does not work without a HttpSessionContextIntegrationFilter earlier on the chain. After a successful authentication it sets a thread-local security context that never gets cleared - meaning that future requests on /go/remoting or /go/agent-websocket will successfully authenticate if they randomly happen to be processed by one of the threads which has a valid security context.

Steps to Reproduce

  1. Start up a server.
  2. Run the following command a bunch of times. It should always return a 403 Forbidden

"curl http://localhost:8153/go/remoting/api/admin/config.xml | grep -B 2 Error"

  1. Start up an agent, and wait about two minutes
  2. Repeat the command from step 2. It should occasionally return a 500 Server Error. This happens when the request was successfully authenticated, and then fails in the GoCD code that is handling the request.

If the server has any artifacts, the URL from step (2) can be changed to a path to that URL. In this case it will sometimes return 403 Forbidden, and sometimes return the artifact itself.

Risk

This allows an attacker without any credentials to read all artifacts or even upload artifacts (combined with #240198 they could use this to execute a stored XSS). While preparing this ticket, I was able to successfully upload a stored XSS file without any credentials by submitting a bunch of POST requests to http://localhost:8153/go/remoting/files/up42/1/up42_stage/1/up42_job/attack_unauthenticated.html

This is also really easy to discover - I stumbled across it when I noticed some requests were randomly being denied as unauthorized. It turns out all of my requests should have been unauthorized!

Recommended Fix

Add httpSessionContextIntegrationFilter immediately before x509ProcessingFilter in the acegi-security.xml file, for the /remoting/ and /agent-websocket/ entries.

This fixes it because the httpSessionContextIntegrationFilter clears the thread-local security context after each request, thus fixing the problem.

The original report as published on HackerOne, by 4cad. 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

The deprecated X509ProcessingFilter set a thread-local security context that was never cleared because HttpSessionContextIntegrationFilter was missing earlier in the filter chain.

Impact

An unauthenticated attacker could read all artifacts or upload artifacts, and combined with another issue could execute a stored XSS; the exploit is probabilistic because it depends on thread reuse.

What the attacker needed

An agent must have logged in; requests must hit a thread with a stale context

The fix

Add httpSessionContextIntegrationFilter immediately before x509ProcessingFilter for the /remoting/ and /agent-websocket/ entries so the thread-local context is cleared after each request.

How it was found

  1. Start the server.
  2. Repeatedly request the remoting config endpoint and confirm it returns 403 Forbidden.
  3. Start an agent and wait about two minutes.
  4. Repeat the request and observe it occasionally returns 500 Server Error when authentication succeeds.
  5. If artifacts exist, request an artifact path and observe it sometimes returns the artifact instead of 403.

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.

When a user logs in, the server often remembers who they are for that request using a temporary note attached to the thread handling it. Here, that note was never cleared after an agent logged in, so later requests that happened to land on the same thread were wrongly treated as logged in. This let someone with no account sometimes read or upload files.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by 4cad

View all

4 more disclosed reports, best first.

More from GoCD

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.