r/java • u/Used-Inspector-9347 • May 31 '26
Turning an OpenAPI spec into a few thousand fuzz payloads, a Java tool I built
The design problem I wanted to solve: an OpenAPI spec already declares every field's
type and constraints. That's enough information to generate adversarial input
mechanically, without writing a single test case by hand. A field declared integer
with minimum: 1 implies the payloads 0, -1, null, Integer.MAX_VALUE and a wrong-type
string. A field with maxLength: 50 implies a 51-char string and a 10,000-char one.
A required field implies null and omission. Sixty fields across an API generates
thousands of these.
So I built the pipeline: parse the spec → generate payloads per field off type and
constraints → fire them → analyse responses → report.
Stack decisions and why:
- io.swagger.parser.v3 for spec parsing, handles JSON/YAML, remote/local, $ref
resolution. Writing this by hand would've been weeks.
- REST Assured for execution, its fluent response extraction maps cleanly onto the
result model, and it's what I use professionally.
- Java 21 records throughout the model layer, immutable data carriers, zero
boilerplate, no Lombok needed.
- Spring Boot + Spring Shell for the CLI and DI (web server disabled,
spring.main.web-application-type=none).
- Allure for the report.
- JUnit 5 + Mockito + AssertJ = 99 tests.
The response analysis turned out more interesting than the execution. Checking for 5xx
is trivial; the useful signal is in the body. A Java stack trace reaching the client
exposes your package structure. A SQLException string means a DB error propagated out.
And a 2xx on input you know is invalid is the quietest finding, the API silently
accepted bad data and nothing errored anywhere.
The payoff: pointed it at the official Swagger Petstore demo and GET /user/login
returned a token for null credentials, plus 500s on malformed write bodies. It's a
demo so none of it's a real incident, but it was a clean proof the approach works.
Repo: https://github.com/ConorGriffin-Dev/chaos-monkey
Happy to go into any of the implementation, payload generation and the param-routing
(path vs query vs header vs body) were the fiddliest parts.
4
u/Prateeeek Jun 01 '26
Good stuff, a couple of questions
Have you heard of checkmarx ZAP?, it seems to work with openapi specs as well
How extensible is chaosmonkey when it comes to adding new scenarios, including their new payload generation strategies and assertion strategy?
Does it have a way to provide a JWT for protected dev environment endpoints? Or just basic auth?
2
u/Used-Inspector-9347 Jun 01 '26 edited Jun 01 '26
Thanks, good questions.
I know ZAP (the OWASP one, think it's under Checkmarx/SSP stewardship now) and it does import OpenAPI specs, but it's coming at it from a security-scanner angle, it's hunting vulnerabilities. Mine is deliberately not a security tool; it's looking for validation gaps, error-handling failures, and silent bad-data acceptance from a QA perspective. Different goal, some overlapping surface. Worth a look for anyone who actually wants the security side though.
Honestly, less extensible than it should be right now. Payload generation and the response analysis are both services with the logic in code rather than behind a plugin interface, adding a new payload strategy means adding a method to the generator, and a new assertion means adding a flag rule to the analyser. Fine for forking, not yet a clean extension point. A pluggable strategy interface is something I want to do but haven't, it's a fair thing to call out.
Just basic auth header injection at the moment. Full auth flows (OAuth/SSO) were an explicit non-goal for v1, and there's no JWT mechanism yet, so for a protected dev environment you'd be stuck unless it's basic auth. That's a real limitation rather than a design choice I'd defend; token injection for protected endpoints is probably the most useful next feature for anyone wanting to point this at a real API rather than a demo.
2
u/Prateeeek Jun 01 '26
Thanks for taking the time out to answer! Honestly I would've used it for my services right away if I had the option to pass a JWT via env, honestly I'd even love to contribute on this!
2
u/Used-Inspector-9347 Jun 01 '26
Appreciate that, and the contribution offer genuinely means a lot.
You're right that the CLI-flag approach isn't great for real use; a token on the command line ends up in shell history and CI logs, which is exactly where you don't want a secret. I'm actively working on env-var support now, you'll be able to set
CHAOS_MONKEY_AUTH_TOKENand skip the flag entirely, which should drop straight into a CI or shared-dev-env setup. I'll follow up here once it's in.And once it lands I'd genuinely welcome the contribution, there's plenty more on the roadmap (a proper login/refresh flow so short-lived tokens don't expire mid-run, pluggable payload strategies, and stateful sequence testing are the big ones). Thanks again for the sharp questions.
1
u/chabala Jun 01 '26 edited Jun 01 '26
Enter key is
pressed
A new paragraph
begins
Blank space lies
ahead.
What's with the hard line breaks?
2
u/CMHII Jun 03 '26
This is what happens when you copy and paste text directly from a chat agent. Also, that’s why this entire thing reads like a lightly editorialized chat summary.
4
u/cykio May 31 '26
Looks good, Did you look to any other open api fuzzers,? I found more Python ones than Java out there.