Fixing 403 auth errors when you replay traffic
Trigger warning: this one is about Java, authentication, and Docker Compose files. If that is not your thing, I am sorry, but they are part of life and they are honestly not that hard to work with. Everything here is open source on our GitHub repo, so you can follow along.
Recording an authenticated Java flow, replaying it, hitting the dreaded 403, and fixing it with a proxymock recommendation.
A little demo app that logs in and calls some APIs
The demo is a Spring Boot service that hands out JWT bearer tokens. A test script logs in once and then makes a few authenticated calls with the token it got back:
./scripts/test.sh localhost:8081
It logs in, grabs the accessToken, and calls GET /api/auth/user three times with Authorization: Bearer <token>. No sweat. That works.
What I actually want is more visibility into what these calls do, and a way to turn them into repeatable tests.
LLM prompt for this step
Run the local demo client script against localhost:8081 and confirm login and subsequent API calls work before recording. Keep credentials local and report status codes and request order.
Recording the traffic with proxymock
proxymock is a free tool that records the traffic going in and out of your app. You run the recorder, tell it the port your app listens on, and point your client at proxymock’s port (4143) instead:
proxymock record --app-port 8081 -- docker compose up
Run the same test script through port 4143, and now I have a recording. proxymock writes one Markdown file per request. If you use AI coding tools, they like reading those directly. If you want to read them as a human, there is a web interface:
proxymock web
I can see the login call and the three user calls, each with its request, response, and headers.
LLM prompt for this step
Start the Docker Compose demo under proxymock recording with app port 8081. Exercise login and the API workflow through the recorder, stop cleanly, and open the recording in proxymock web. Identify where the login response token is reused.
Replaying it, and the dreaded 403
What I really want is to replay this traffic so I have some test automation around the code. So I run it back against my local app:
proxymock replay --in ./proxymock --test-against localhost:8081
Except this did not work right. The first call worked, but the rest did not. We got the dreaded 403.
If you have ever tried to diagnose one of these, you know the pain. You look in the response and there is nothing there. You look in the headers and they do not tell you what is going on.
The information is here, you are just not allowed to see that data. And the reason is we are replaying with the old token. The recording captured the bearer token that was minted at record time, that token has since expired, and the replay is faithfully resending it on every call after the login.
LLM prompt for this step
Replay the saved auth workflow against localhost:8081 using the installed client's supported URL format. Locate the first 403 and compare its token, cookie, or session references with the login response, without exposing secret values.
Reviewing the recommendations
So to fix that, you come into the Recommendations panel. proxymock already analyzed the replay, and there is a recommendation that identifies the OAuth handshake. It found the access token and highlighted it. Accept that one.
There are other recommendations too. proxymock noticed an email address in the traffic, for instance. I happen to like that email and want it to pass through unchanged, so I leave that recommendation alone.
Now run the replay one more time:
proxymock replay --in ./proxymock --test-against localhost:8081
This time the console says Applied 1 active blueprint(s) to replay, and I get a 100% match rate. Everything works, because the recommendation made sure the token the app issues on the first call is the token used on all the rest.
LLM prompt for this step
Using the recording in ./proxymock and the earlier replay against localhost:8081 that returned 403 after the login call, open the replay's recommendations in proxymock web (`proxymock web`, Recommendations panel). Accept only the recommendation that identifies the OAuth handshake and its access token, and leave the others, such as the email address recommendation, unaccepted. If you cannot operate the panel yourself, stop and ask me to accept it. Then rerun `proxymock replay --in ./proxymock --test-against localhost:8081` and confirm the console reports `Applied 1 active blueprint(s) to replay` and a 100% match rate. Check `proxymock replay --help` before adapting the command. Report which recommendation was accepted, the commands you ran, the match rate, and anything you could not verify.
What the recommendation actually did
If you are curious, proxymock saved the fix as a blueprint you can open and inspect. Here is the chain it built:
(networkaddr CONTAINS "localhost"
AND location IS "/api/auth/session/login"
AND command IS "POST")
| res_body()
| json_path(path=accessToken)
| smart_replace_recorded(overwrite=true)
It goes into the response body of the login endpoint, uses a JSON path to grab the accessToken, and runs a smart replace. Because the smart replace matches on the token value, it rewrites the Authorization header on every protected request without me naming each one.
There is a whole library of these transforms if you want to do more, but the recommendations are a quick and dirty way to get up and running. This is the same token correlation our cloud product does, running locally on your laptop.
LLM prompt for this step
Review the recommended login-token blueprint and its host, path, and method scope. Apply only the necessary token correlation, rerun the same recording, and verify both authenticated calls and an invalid-session negative case. Report remaining mismatches.
Try it yourself
The full walkthrough lives in the proxymock docs, and the demo app is on GitHub. There is a lot more you can do with the recorded data. If you have questions, reach out at proxymock.io.
Run this workflow with an LLM
Give this prompt to a coding assistant with access to your project and this article. Supply environment-specific values it cannot discover.
Whole-workflow LLM prompt
Read https://speedscale.com/blog/fix-403-auth-errors-traffic-replay-proxymock/ and inspect my project instructions first. Use the demo's login and API workflow to reproduce a replay 403. Compare the recorded and candidate login token flow, inspect the scoped request blueprint recommendation, and rerun the same recording to verify session values propagate correctly without weakening authentication. Check installed tool help before adapting commands. Report the checks actually run, their results, and anything you could not verify.
Frequently asked questions
Why does an old token fail during replay?
A recorded bearer token may be expired or invalid for the replay environment. Replaying the login call can obtain a new token, but later requests must actually use it. Correlate the current login response into the protected requests. A 403 alone does not diagnose expiration; the status can also reflect authorization rules or application-specific error handling.
How do I tell a missing correlation rule from an authorization defect?
Compare the token issued during the replay with the value sent on the failing request. If replay still sends the recorded value, fix correlation. If it sends the current value, inspect the service’s validation and authorization decisions, including audience, issuer, roles, and scopes. Avoid masking a permission failure by accepting any token or ignoring the protected response.
How do I prove the transform actually ran?
Use the blueprint preview to inspect changes, then require the saved blueprint during replay with --require-blueprint followed by its exact name. The command fails if it is missing or none of its chains run. That proves some activity, not that every rule ran or authorization is correct; inspect the resulting request and keep response assertions.
Sources: Creating and verifying blueprints, JWT replay authentication.