badday 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +270 -0
- package/dist/cli.js +4633 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Umar Farooq
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
# badday
|
|
2
|
+
|
|
3
|
+
Give your backend a bad day before production does.
|
|
4
|
+
|
|
5
|
+
Find out if your backend double-charges, leaks another user's data or falls over on a bad request, before a customer does.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npx badday demo
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
That command starts a small shop backend with known defects, runs 31 checks against it and prints what broke. It needs no setup and takes about 4 seconds.
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
BROKEN A customer who double-clicks "Pay" is charged twice.
|
|
15
|
+
We sent the same order 20 times at once, with one idempotency key. Your app created
|
|
16
|
+
20 orders.
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Hand it to your coding agent
|
|
20
|
+
|
|
21
|
+
Most people never type a badday command. Start your backend, then paste this into Claude Code, Cursor or any other coding agent:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
Run `npx badday init --agent` and follow the brief it prints. Write badday.config.json
|
|
25
|
+
for this backend, run `npx badday validate` until it reports no problem, then run
|
|
26
|
+
`npx badday run --json`. For each check that fails, read its evidence and fixPrompt and
|
|
27
|
+
fix the backend, not the config. Run it again until nothing fails, then tell me which
|
|
28
|
+
checks were not tested and what each one needs.
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The agent reads your routes and auth, writes the config and fixes what breaks. badday refuses any host that is not on your machine, so the agent cannot point it at production by accident.
|
|
32
|
+
|
|
33
|
+
If you use Claude Code, `npx badday init --skill` writes a skill to `.claude/skills/badday/`. After that, "test this backend with badday" is enough.
|
|
34
|
+
|
|
35
|
+
badday is a command-line tool. You point it at a running HTTP backend. It sends the traffic that breaks backends in production, then reports which promises the backend broke, with the requests and responses as evidence. It never reads your code, so it works against Express, Django, Rails, Go or anything else that speaks HTTP.
|
|
36
|
+
|
|
37
|
+
## What it checks
|
|
38
|
+
|
|
39
|
+
| Pack | Checks | It sends |
|
|
40
|
+
|---|---|---|
|
|
41
|
+
| Replay | 8 | The same request again: 20 copies at once, a late retry, a retry during a running request, a retry after a dropped connection, one user's key sent by another |
|
|
42
|
+
| Webhooks | 7 | One event delivered 3 times, 5 copies at once, a wrong signature, no signature, an old timestamp, a body changed after signing, an unknown event type |
|
|
43
|
+
| Pagination and input | 9 | Garbage and damaged cursors, another user's cursor, `limit=100000`, bad limits, a list walk while records arrive, a 10 MB body, broken JSON |
|
|
44
|
+
| Access | 7 | Every route with no credentials and with a made-up token, one user reading, changing, deleting and listing another user's records, fields only the server may set |
|
|
45
|
+
|
|
46
|
+
`npx badday list` prints every check with the promise it tests.
|
|
47
|
+
|
|
48
|
+
What runs depends on what your backend has. The access and input packs run against almost any backend: they need a create route and two test users. The replay pack needs an idempotency key that your backend reads, in a header or a body field. The webhook pack needs a signed webhook route and a list that shows what an event did. A pack your backend has nothing for reports "not tested", with the reason.
|
|
49
|
+
|
|
50
|
+
Each result is one of four verdicts: kept, broken, warning or not tested. A check that could not run is never counted as kept.
|
|
51
|
+
|
|
52
|
+
## Test your own app
|
|
53
|
+
|
|
54
|
+
Start your app on your machine, then pick the path that fits you.
|
|
55
|
+
|
|
56
|
+
### Let badday watch your app
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
npx badday record --target http://localhost:3000
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
This is the path that needs the least from you. badday starts a local proxy on port 4010 that passes everything on to your backend. Point your frontend or your API client at the proxy, then use your app as a first test user: log in, create one record, open it, change it, look at the list, delete one. Press Enter, do the same as a second user, and press Enter again.
|
|
63
|
+
|
|
64
|
+
badday writes `badday.config.json` from what it saw: the routes, the credentials of both users, the wrapper around a record, the field that holds the id, and the routes your app itself reads with no login. Then it sends a few test requests to your running backend to learn what a recording cannot show, such as the page size parameter of the list and how the list reaches a second page. It prints what it learned and what it could not work out.
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
npx badday run
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
If you cannot change where your frontend sends its requests, export a HAR file per user from the network tab of your browser:
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
npx badday record --har alice.har,bob.har
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Browsers leave credentials out of a HAR file by default. In Chrome, turn on "Allow to generate HAR with sensitive data" in the DevTools settings first.
|
|
77
|
+
|
|
78
|
+
A recording cannot show three things, and badday does not guess them: if two identical records are legal (`duplicates`), how to make a request slow (`create.slow`), and if a list that shows one user the records of another is meant to (`shared`). It tells you when one of them matters.
|
|
79
|
+
|
|
80
|
+
### You built the app with an AI tool
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
npx badday
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
With no config in the folder, badday asks a few questions in plain words. It finds your app on the usual local ports, and looks for an API description at `/openapi.json`, `/swagger.json`, `/api-docs` and `/docs`. If it finds one, it writes the config from it and asks you for the token of a test user.
|
|
87
|
+
|
|
88
|
+
If your app publishes no API description, badday prints a short prompt to paste into Cursor, Claude Code or Lovable. Your AI tool then writes the config.
|
|
89
|
+
|
|
90
|
+
Each failure comes with a fix prompt: a paragraph that names the defect, the evidence and the standard remedy, written to paste back into your AI tool.
|
|
91
|
+
|
|
92
|
+
### You are a coding agent
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
npx badday init --agent
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
This prints a brief with the loop, the place to look for routes and auth, every config field and the shape of the output. The loop is short: write `badday.config.json`, run `npx badday validate` until it reports no problem, then run `npx badday run --json`. `validate` names the path, the problem and the fix for each error.
|
|
99
|
+
|
|
100
|
+
`npx badday init --skill` writes the same procedure as a Claude Code skill to `.claude/skills/badday/SKILL.md`, so later sessions find it without a prompt.
|
|
101
|
+
|
|
102
|
+
### You are a developer
|
|
103
|
+
|
|
104
|
+
Write `badday.config.json`:
|
|
105
|
+
|
|
106
|
+
```json
|
|
107
|
+
{
|
|
108
|
+
"baseUrl": "http://localhost:3000",
|
|
109
|
+
"actors": {
|
|
110
|
+
"alice": { "headers": { "Authorization": "Bearer alice-token" } },
|
|
111
|
+
"bob": { "headers": { "Authorization": "Bearer bob-token" } }
|
|
112
|
+
},
|
|
113
|
+
"resources": [{
|
|
114
|
+
"name": "orders",
|
|
115
|
+
"create": { "method": "POST", "path": "/orders", "body": { "item": "pizza", "qty": 1 } },
|
|
116
|
+
"get": "/orders/:id",
|
|
117
|
+
"list": { "path": "/orders", "limitParam": "limit" },
|
|
118
|
+
"update": { "method": "PATCH", "path": "/orders/:id", "body": { "qty": 2 } },
|
|
119
|
+
"remove": { "method": "DELETE", "path": "/orders/:id" },
|
|
120
|
+
"idempotencyHeader": "Idempotency-Key",
|
|
121
|
+
"protectedFields": ["userId", "total", "status"],
|
|
122
|
+
"markerField": "note"
|
|
123
|
+
}],
|
|
124
|
+
"webhooks": [{
|
|
125
|
+
"path": "/webhooks/payment",
|
|
126
|
+
"signing": { "scheme": "stripe", "secret": "whsec_test" },
|
|
127
|
+
"event": { "type": "payment.succeeded", "data": { "orderId": "$orders.id" } },
|
|
128
|
+
"effect": { "list": "/payments" }
|
|
129
|
+
}]
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
One resource description drives 24 checks, and one webhook drives 7 more. You write no test code. The file can also be `badday.config.mjs` or, on Node 22.18 and later, `badday.config.ts`.
|
|
134
|
+
|
|
135
|
+
### Your backend does not look like that example
|
|
136
|
+
|
|
137
|
+
Few do. These fields describe the shapes real backends have:
|
|
138
|
+
|
|
139
|
+
| Your backend | Set |
|
|
140
|
+
|---|---|
|
|
141
|
+
| Wraps the record in requests and responses, as `{ "article": {...} }` | `envelope: "article"` |
|
|
142
|
+
| Wraps only responses, under `data` or the resource name | Nothing. badday finds the record |
|
|
143
|
+
| Finds records by a slug or a name, not an id | `idField: "slug"` |
|
|
144
|
+
| Answers a create with a message and no record | `markerField` on a text field. badday finds its record in the list. If the client picks the lookup name, set `idField` and `markerField` to the same field |
|
|
145
|
+
| Pages by page number or by offset | `list.pageParam` or `list.offsetParam` |
|
|
146
|
+
| Takes the idempotency key in the body | `idempotencyField: "transaction_id"` |
|
|
147
|
+
| Has a feed or a detail page that everyone may read | `public: ["list", "get"]`, or `shared` if it needs a login |
|
|
148
|
+
| Answers a webhook first and handles it in a queue | `effect.settleMs` |
|
|
149
|
+
|
|
150
|
+
A test user usually needs a login, and tokens expire. A `badday.config.mjs` can log in by itself on each run:
|
|
151
|
+
|
|
152
|
+
```js
|
|
153
|
+
const baseUrl = 'http://localhost:3000/api'
|
|
154
|
+
|
|
155
|
+
async function actor(email, password) {
|
|
156
|
+
const res = await fetch(baseUrl + '/users/login', {
|
|
157
|
+
method: 'POST',
|
|
158
|
+
headers: { 'Content-Type': 'application/json' },
|
|
159
|
+
body: JSON.stringify({ user: { email, password } }),
|
|
160
|
+
})
|
|
161
|
+
const { user } = await res.json()
|
|
162
|
+
return { headers: { Authorization: 'Token ' + user.token } }
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export default {
|
|
166
|
+
baseUrl,
|
|
167
|
+
actors: { alice: await actor('alice@example.test', 'pw-alice'), bob: await actor('bob@example.test', 'pw-bob') },
|
|
168
|
+
resources: [{
|
|
169
|
+
name: 'articles',
|
|
170
|
+
envelope: 'article',
|
|
171
|
+
idField: 'slug',
|
|
172
|
+
markerField: 'title',
|
|
173
|
+
create: { path: '/articles', body: { article: { title: 'test', description: 'test', body: 'test' } } },
|
|
174
|
+
get: '/articles/:id',
|
|
175
|
+
list: { path: '/articles', limitParam: 'limit', offsetParam: 'offset' },
|
|
176
|
+
update: { method: 'PUT', path: '/articles/:id', body: { article: { body: 'changed' } } },
|
|
177
|
+
remove: '/articles/:id',
|
|
178
|
+
public: ['list', 'get'],
|
|
179
|
+
}],
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
npx badday run # every check
|
|
185
|
+
npx badday run --only replay,cross-user-read
|
|
186
|
+
npx badday run --skip webhooks
|
|
187
|
+
npx badday run --detail # print the requests of each failure
|
|
188
|
+
npx badday run --json # one JSON document, for CI and agents
|
|
189
|
+
npx badday init --from openapi.json # draft a config from an OpenAPI file or URL
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
`run` also writes `badday-report.html`, one self-contained file with every request and response. `--no-html` turns that off.
|
|
193
|
+
|
|
194
|
+
Exit code 0 means no check failed, 1 means a check failed, and 2 means the config or the target was not usable.
|
|
195
|
+
|
|
196
|
+
## Safety
|
|
197
|
+
|
|
198
|
+
badday creates records and sends hostile input. It is built to be run against your own machine.
|
|
199
|
+
|
|
200
|
+
- It refuses any host that is not `localhost` or a private address. `--i-own-this-server <hostname>` lifts that, and you have to name the host.
|
|
201
|
+
- Before it starts, it prints the most records it can create.
|
|
202
|
+
- If a resource has a `remove` route, badday deletes what it created. If not, the report says how many records it left behind. It also counts the create requests that succeeded without naming a record, because badday cannot delete what those made.
|
|
203
|
+
- After each check, badday reads your list once. If your app has stopped answering, badday waits for it, and reports the stall against the check that caused it.
|
|
204
|
+
- It never runs a destructive request against a record it did not create.
|
|
205
|
+
|
|
206
|
+
Running badday against a server you do not own can be illegal. Do not do it.
|
|
207
|
+
|
|
208
|
+
## Standards
|
|
209
|
+
|
|
210
|
+
The HTML report has a tab for HIPAA, GDPR, PCI DSS, SOC 2 and the OWASP API Top 10. Each tab regroups the same results by the control they give evidence for.
|
|
211
|
+
|
|
212
|
+
Read those tabs for what they are. Most of each standard is about the organisation: contracts, training, backups, encryption of stored data. A tool that sends HTTP requests sees none of that, and every tab lists those areas under "Needs a person". What badday produces is evidence for the technical controls that show at the HTTP boundary. The mapping is a draft, written by developers. It is not a compliance assessment, and nobody has yet checked the citations against the source texts.
|
|
213
|
+
|
|
214
|
+
## Tried on code we did not write
|
|
215
|
+
|
|
216
|
+
Every config below was written by `badday record` from a scripted user session. Nobody described the backend by hand. `targets/` holds each session, the compose file that starts the target, and the results.
|
|
217
|
+
|
|
218
|
+
[OWASP Juice Shop](https://github.com/juice-shop/juice-shop) is a shop with planted defects. The session added, changed and deleted a delivery address as two customers.
|
|
219
|
+
|
|
220
|
+
| Check | Result |
|
|
221
|
+
|---|---|
|
|
222
|
+
| `cross-user-update` | broken. Bob sends a `PUT` for Alice's address and gets 200. The address now belongs to Bob, and Alice gets 400 when she asks for it |
|
|
223
|
+
| `broken-json` | broken. Cut-off JSON gets a 500 |
|
|
224
|
+
| `error-leak` | broken. The 500 carries a stack trace and file paths |
|
|
225
|
+
| `cross-user-read`, `cross-user-delete`, `cross-user-list` | kept |
|
|
226
|
+
| `no-credentials`, `garbage-token`, `protected-fields`, `body-too-large` | kept |
|
|
227
|
+
|
|
228
|
+
[VAmPI](https://github.com/erev0s/VAmPI) is an API with known defects. Its compose file runs one secure and one vulnerable instance of the same code. `targets/vampi` holds the config and both results.
|
|
229
|
+
|
|
230
|
+
| Check | Secure instance | Vulnerable instance |
|
|
231
|
+
|---|---|---|
|
|
232
|
+
| `cross-user-read` | kept. Bob gets 404 for Alice's book | broken. Bob gets 200 and reads Alice's secret |
|
|
233
|
+
| `no-credentials`, `garbage-token` | kept | kept |
|
|
234
|
+
| `body-too-large` | broken. A 10 MB body is accepted | broken |
|
|
235
|
+
| `keyless-duplicate`, `broken-json`, `error-leak` | kept | kept |
|
|
236
|
+
|
|
237
|
+
The other 24 checks report "not tested" there. VAmPI has no idempotency key, no webhook, no update or delete for books and no paging, and its other planted defects, such as SQL injection, are outside what badday tests. That is one catch, and the one the two instances differ in.
|
|
238
|
+
|
|
239
|
+
badday also ran this way on five projects that are not vulnerable on purpose. Their results go to the maintainers first and are not listed here.
|
|
240
|
+
|
|
241
|
+
## Limits of version 0.1
|
|
242
|
+
|
|
243
|
+
- `badday record` learns resources that have a create route and at least one more route on the same path. It does not learn webhooks, and it stores the tokens it saw, which expire.
|
|
244
|
+
|
|
245
|
+
- The wizard takes a pasted token or cookie. It cannot log in with an email and a password yet. A `badday.config.mjs` can.
|
|
246
|
+
- The webhook pack sends an event that names one of your own records. A handler that looks up an object at Stripe, or acts only on an id that Stripe issued earlier, gives it nothing to count. Those webhooks report a warning, not a result.
|
|
247
|
+
- A backend that limits request rates answers 429 to badday's bursts. badday does not tell that apart from a refusal yet. Raise the limit for the test run.
|
|
248
|
+
- The path of a route takes one placeholder, `:id`. For a nested route such as `/events/7/tickets/:id`, create the parent in a `.mjs` config and write its id into the path.
|
|
249
|
+
- `init --from` reads OpenAPI in JSON, not YAML.
|
|
250
|
+
- Two replay checks need a slow variant of your create route in the config (`create.slow`), and report "not tested" without it.
|
|
251
|
+
- Webhook signing supports the Stripe format and a plain HMAC-SHA256 header.
|
|
252
|
+
- The privacy and transport packs, a Vitest adapter and a GitHub Action are planned for later versions.
|
|
253
|
+
|
|
254
|
+
## Development
|
|
255
|
+
|
|
256
|
+
```
|
|
257
|
+
pnpm install
|
|
258
|
+
pnpm test # every check on both fixtures
|
|
259
|
+
pnpm status # what exists and what is proven
|
|
260
|
+
pnpm build # bundle the CLI to dist/cli.js
|
|
261
|
+
node dist/cli.js demo
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Node 24 runs the TypeScript sources directly. The published bundle runs on Node 20 and later and has no runtime dependencies.
|
|
265
|
+
|
|
266
|
+
The repository holds two fixtures: `fixtures/shop-broken`, a small backend that has every defect, and `fixtures/shop-fixed`, the same backend with none. A check counts as proven only when it fails on the broken shop and passes on the fixed one. A check that has never refused anything proves nothing. `pnpm test --repeat 20` runs each check 20 times, for the ones that depend on timing.
|
|
267
|
+
|
|
268
|
+
## Licence
|
|
269
|
+
|
|
270
|
+
MIT.
|