Skip to content

Commit 1021494

Browse files
fix(audits/server): Status code for mutations through GET should be between 400 and 499 (#19)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 9c5e8d2 commit 1021494

File tree

3 files changed

+69
-71
lines changed

3 files changed

+69
-71
lines changed

implementations/apollo-server/README.md

Lines changed: 66 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ _* This report was auto-generated by graphql-http_
33
# GraphQL over HTTP audit report
44

55
- **73** audits in total
6-
-**35** pass
7-
- ⚠️ **38** warnings (optional)
6+
-**36** pass
7+
- ⚠️ **37** warnings (optional)
88

99
## Passing
1010
1. SHOULD accept application/graphql-response+json and match the content-type
@@ -13,35 +13,36 @@ _* This report was auto-generated by graphql-http_
1313
4. MUST accept utf-8 encoding
1414
5. MUST assume utf-8 if encoding is unspecified
1515
6. MUST accept POST requests
16-
7. SHOULD respond with 4xx status code if content-type is not supplied on POST requests
17-
8. MUST accept application/json POST requests
18-
9. MUST require a request body on POST
19-
10. SHOULD use 400 status code on missing {query} parameter when accepting application/graphql-response+json
20-
11. SHOULD use 400 status code on object {query} parameter when accepting application/graphql-response+json
21-
12. SHOULD use 400 status code on number {query} parameter when accepting application/graphql-response+json
22-
13. SHOULD use 400 status code on boolean {query} parameter when accepting application/graphql-response+json
23-
14. SHOULD use 400 status code on array {query} parameter when accepting application/graphql-response+json
24-
15. SHOULD allow string {query} parameter when accepting application/graphql-response+json
25-
16. MUST allow string {query} parameter when accepting application/json
26-
17. SHOULD allow string {operationName} parameter when accepting application/graphql-response+json
27-
18. MUST allow string {operationName} parameter when accepting application/json
28-
19. SHOULD use 400 status code on string {variables} parameter when accepting application/graphql-response+json
29-
20. SHOULD allow map {variables} parameter when accepting application/graphql-response+json
30-
21. MUST allow map {variables} parameter when accepting application/json
31-
22. SHOULD use 400 status code on string {extensions} parameter when accepting application/graphql-response+json
32-
23. SHOULD allow map {extensions} parameter when accepting application/graphql-response+json
33-
24. MUST allow map {extensions} parameter when accepting application/json
34-
25. SHOULD use 4xx or 5xx status codes on JSON parsing failure when accepting application/graphql-response+json
35-
26. SHOULD use 400 status code on JSON parsing failure when accepting application/graphql-response+json
36-
27. SHOULD use 4xx or 5xx status codes if parameters are invalid when accepting application/graphql-response+json
37-
28. SHOULD use 400 status code if parameters are invalid when accepting application/graphql-response+json
38-
29. SHOULD not contain the data entry if parameters are invalid when accepting application/graphql-response+json
39-
30. SHOULD use 4xx or 5xx status codes on document parsing failure when accepting application/graphql-response+json
40-
31. SHOULD use 400 status code on document parsing failure when accepting application/graphql-response+json
41-
32. SHOULD not contain the data entry on document parsing failure when accepting application/graphql-response+json
42-
33. SHOULD use 4xx or 5xx status codes on document validation failure when accepting application/graphql-response+json
43-
34. SHOULD use 400 status code on document validation failure when accepting application/graphql-response+json
44-
35. SHOULD not contain the data entry on document validation failure when accepting application/graphql-response+json
16+
7. MAY NOT allow executing mutations on GET requests
17+
8. SHOULD respond with 4xx status code if content-type is not supplied on POST requests
18+
9. MUST accept application/json POST requests
19+
10. MUST require a request body on POST
20+
11. SHOULD use 400 status code on missing {query} parameter when accepting application/graphql-response+json
21+
12. SHOULD use 400 status code on object {query} parameter when accepting application/graphql-response+json
22+
13. SHOULD use 400 status code on number {query} parameter when accepting application/graphql-response+json
23+
14. SHOULD use 400 status code on boolean {query} parameter when accepting application/graphql-response+json
24+
15. SHOULD use 400 status code on array {query} parameter when accepting application/graphql-response+json
25+
16. SHOULD allow string {query} parameter when accepting application/graphql-response+json
26+
17. MUST allow string {query} parameter when accepting application/json
27+
18. SHOULD allow string {operationName} parameter when accepting application/graphql-response+json
28+
19. MUST allow string {operationName} parameter when accepting application/json
29+
20. SHOULD use 400 status code on string {variables} parameter when accepting application/graphql-response+json
30+
21. SHOULD allow map {variables} parameter when accepting application/graphql-response+json
31+
22. MUST allow map {variables} parameter when accepting application/json
32+
23. SHOULD use 400 status code on string {extensions} parameter when accepting application/graphql-response+json
33+
24. SHOULD allow map {extensions} parameter when accepting application/graphql-response+json
34+
25. MUST allow map {extensions} parameter when accepting application/json
35+
26. SHOULD use 4xx or 5xx status codes on JSON parsing failure when accepting application/graphql-response+json
36+
27. SHOULD use 400 status code on JSON parsing failure when accepting application/graphql-response+json
37+
28. SHOULD use 4xx or 5xx status codes if parameters are invalid when accepting application/graphql-response+json
38+
29. SHOULD use 400 status code if parameters are invalid when accepting application/graphql-response+json
39+
30. SHOULD not contain the data entry if parameters are invalid when accepting application/graphql-response+json
40+
31. SHOULD use 4xx or 5xx status codes on document parsing failure when accepting application/graphql-response+json
41+
32. SHOULD use 400 status code on document parsing failure when accepting application/graphql-response+json
42+
33. SHOULD not contain the data entry on document parsing failure when accepting application/graphql-response+json
43+
34. SHOULD use 4xx or 5xx status codes on document validation failure when accepting application/graphql-response+json
44+
35. SHOULD use 400 status code on document validation failure when accepting application/graphql-response+json
45+
36. SHOULD not contain the data entry on document validation failure when accepting application/graphql-response+json
4546

4647
## Warnings
4748
The server _SHOULD_ support these, but is not required.
@@ -57,143 +58,139 @@ Content-Type header "application/json; charset=utf-8" does not contain "applicat
5758
```
5859
Status code 400 is not 200
5960
```
60-
4. MAY NOT allow executing mutations on GET requests<br />
61-
```
62-
Status code 400 is not 405
63-
```
64-
5. SHOULD use 200 status code with errors field on missing {query} parameter when accepting application/json<br />
61+
4. SHOULD use 200 status code with errors field on missing {query} parameter when accepting application/json<br />
6562
```
6663
Status code 400 is not 200
6764
```
68-
6. SHOULD use 200 status code with errors field on object {query} parameter when accepting application/json<br />
65+
5. SHOULD use 200 status code with errors field on object {query} parameter when accepting application/json<br />
6966
```
7067
Status code 400 is not 200
7168
```
72-
7. SHOULD use 200 status code with errors field on number {query} parameter when accepting application/json<br />
69+
6. SHOULD use 200 status code with errors field on number {query} parameter when accepting application/json<br />
7370
```
7471
Status code 400 is not 200
7572
```
76-
8. SHOULD use 200 status code with errors field on boolean {query} parameter when accepting application/json<br />
73+
7. SHOULD use 200 status code with errors field on boolean {query} parameter when accepting application/json<br />
7774
```
7875
Status code 400 is not 200
7976
```
80-
9. SHOULD use 200 status code with errors field on array {query} parameter when accepting application/json<br />
77+
8. SHOULD use 200 status code with errors field on array {query} parameter when accepting application/json<br />
8178
```
8279
Status code 400 is not 200
8380
```
84-
10. SHOULD use 400 status code on object {operationName} parameter when accepting application/graphql-response+json<br />
81+
9. SHOULD use 400 status code on object {operationName} parameter when accepting application/graphql-response+json<br />
8582
```
8683
Status code 200 is not 400
8784
```
88-
11. SHOULD use 400 status code on number {operationName} parameter when accepting application/graphql-response+json<br />
85+
10. SHOULD use 400 status code on number {operationName} parameter when accepting application/graphql-response+json<br />
8986
```
9087
Status code 200 is not 400
9188
```
92-
12. SHOULD use 400 status code on boolean {operationName} parameter when accepting application/graphql-response+json<br />
89+
11. SHOULD use 400 status code on boolean {operationName} parameter when accepting application/graphql-response+json<br />
9390
```
9491
Status code 200 is not 400
9592
```
96-
13. SHOULD use 400 status code on array {operationName} parameter when accepting application/graphql-response+json<br />
93+
12. SHOULD use 400 status code on array {operationName} parameter when accepting application/graphql-response+json<br />
9794
```
9895
Status code 200 is not 400
9996
```
100-
14. SHOULD use 200 status code with errors field on object {operationName} parameter when accepting application/json<br />
97+
13. SHOULD use 200 status code with errors field on object {operationName} parameter when accepting application/json<br />
10198
```
10299
Execution result {"data":{"__typename":"Query"}} does not have a property 'errors'
103100
```
104-
15. SHOULD use 200 status code with errors field on number {operationName} parameter when accepting application/json<br />
101+
14. SHOULD use 200 status code with errors field on number {operationName} parameter when accepting application/json<br />
105102
```
106103
Execution result {"data":{"__typename":"Query"}} does not have a property 'errors'
107104
```
108-
16. SHOULD use 200 status code with errors field on boolean {operationName} parameter when accepting application/json<br />
105+
15. SHOULD use 200 status code with errors field on boolean {operationName} parameter when accepting application/json<br />
109106
```
110107
Execution result {"data":{"__typename":"Query"}} does not have a property 'errors'
111108
```
112-
17. SHOULD use 200 status code with errors field on array {operationName} parameter when accepting application/json<br />
109+
16. SHOULD use 200 status code with errors field on array {operationName} parameter when accepting application/json<br />
113110
```
114111
Execution result {"data":{"__typename":"Query"}} does not have a property 'errors'
115112
```
116-
18. SHOULD use 400 status code on number {variables} parameter when accepting application/graphql-response+json<br />
113+
17. SHOULD use 400 status code on number {variables} parameter when accepting application/graphql-response+json<br />
117114
```
118115
Status code 200 is not 400
119116
```
120-
19. SHOULD use 400 status code on boolean {variables} parameter when accepting application/graphql-response+json<br />
117+
18. SHOULD use 400 status code on boolean {variables} parameter when accepting application/graphql-response+json<br />
121118
```
122119
Status code 200 is not 400
123120
```
124-
20. SHOULD use 400 status code on array {variables} parameter when accepting application/graphql-response+json<br />
121+
19. SHOULD use 400 status code on array {variables} parameter when accepting application/graphql-response+json<br />
125122
```
126123
Status code 200 is not 400
127124
```
128-
21. SHOULD use 200 status code with errors field on string {variables} parameter when accepting application/json<br />
125+
20. SHOULD use 200 status code with errors field on string {variables} parameter when accepting application/json<br />
129126
```
130127
Status code 400 is not 200
131128
```
132-
22. SHOULD use 200 status code with errors field on number {variables} parameter when accepting application/json<br />
129+
21. SHOULD use 200 status code with errors field on number {variables} parameter when accepting application/json<br />
133130
```
134131
Execution result {"data":{"__typename":"Query"}} does not have a property 'errors'
135132
```
136-
23. SHOULD use 200 status code with errors field on boolean {variables} parameter when accepting application/json<br />
133+
22. SHOULD use 200 status code with errors field on boolean {variables} parameter when accepting application/json<br />
137134
```
138135
Execution result {"data":{"__typename":"Query"}} does not have a property 'errors'
139136
```
140-
24. SHOULD use 200 status code with errors field on array {variables} parameter when accepting application/json<br />
137+
23. SHOULD use 200 status code with errors field on array {variables} parameter when accepting application/json<br />
141138
```
142139
Execution result {"data":{"__typename":"Query"}} does not have a property 'errors'
143140
```
144-
25. MAY allow URL-encoded JSON string {variables} parameter in GETs when accepting application/graphql-response+json<br />
141+
24. MAY allow URL-encoded JSON string {variables} parameter in GETs when accepting application/graphql-response+json<br />
145142
```
146143
Status code 400 is not 200
147144
```
148-
26. MAY allow URL-encoded JSON string {variables} parameter in GETs when accepting application/json<br />
145+
25. MAY allow URL-encoded JSON string {variables} parameter in GETs when accepting application/json<br />
149146
```
150147
Status code 400 is not 200
151148
```
152-
27. SHOULD use 400 status code on number {extensions} parameter when accepting application/graphql-response+json<br />
149+
26. SHOULD use 400 status code on number {extensions} parameter when accepting application/graphql-response+json<br />
153150
```
154151
Status code 200 is not 400
155152
```
156-
28. SHOULD use 400 status code on boolean {extensions} parameter when accepting application/graphql-response+json<br />
153+
27. SHOULD use 400 status code on boolean {extensions} parameter when accepting application/graphql-response+json<br />
157154
```
158155
Status code 200 is not 400
159156
```
160-
29. SHOULD use 400 status code on array {extensions} parameter when accepting application/graphql-response+json<br />
157+
28. SHOULD use 400 status code on array {extensions} parameter when accepting application/graphql-response+json<br />
161158
```
162159
Status code 200 is not 400
163160
```
164-
30. SHOULD use 200 status code with errors field on string {extensions} parameter when accepting application/json<br />
161+
29. SHOULD use 200 status code with errors field on string {extensions} parameter when accepting application/json<br />
165162
```
166163
Status code 400 is not 200
167164
```
168-
31. SHOULD use 200 status code with errors field on number {extensions} parameter when accepting application/json<br />
165+
30. SHOULD use 200 status code with errors field on number {extensions} parameter when accepting application/json<br />
169166
```
170167
Execution result {"data":{"__typename":"Query"}} does not have a property 'errors'
171168
```
172-
32. SHOULD use 200 status code with errors field on boolean {extensions} parameter when accepting application/json<br />
169+
31. SHOULD use 200 status code with errors field on boolean {extensions} parameter when accepting application/json<br />
173170
```
174171
Execution result {"data":{"__typename":"Query"}} does not have a property 'errors'
175172
```
176-
33. SHOULD use 200 status code with errors field on array {extensions} parameter when accepting application/json<br />
173+
32. SHOULD use 200 status code with errors field on array {extensions} parameter when accepting application/json<br />
177174
```
178175
Execution result {"data":{"__typename":"Query"}} does not have a property 'errors'
179176
```
180-
34. SHOULD use 200 status code on JSON parsing failure when accepting application/json<br />
177+
33. SHOULD use 200 status code on JSON parsing failure when accepting application/json<br />
181178
```
182179
Status code 400 is not 200
183180
```
184-
35. SHOULD use 200 status code if parameters are invalid when accepting application/json<br />
181+
34. SHOULD use 200 status code if parameters are invalid when accepting application/json<br />
185182
```
186183
Status code 400 is not 200
187184
```
188-
36. SHOULD use 200 status code on document parsing failure when accepting application/json<br />
185+
35. SHOULD use 200 status code on document parsing failure when accepting application/json<br />
189186
```
190187
Status code 400 is not 200
191188
```
192-
37. SHOULD use 200 status code on document validation failure when accepting application/json<br />
189+
36. SHOULD use 200 status code on document validation failure when accepting application/json<br />
193190
```
194191
Status code 400 is not 200
195192
```
196-
38. SHOULD not contain the data entry on JSON parsing failure when accepting application/graphql-response+json<br />
193+
37. SHOULD not contain the data entry on JSON parsing failure when accepting application/graphql-response+json<br />
197194
```
198195
Response body is not valid JSON. Got "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<title>Error</title>\n</head>\n<body>\n<pre>SyntaxError: Unexpected end of JSON input<br> &nbsp; &nbsp;at JSON.parse (&lt;anonymous&gt;)<br> &nbsp; &nbsp;at parse (/home/runner/work/graphql-http/graphql-http/node_modules/body-parser/lib/types/json.js:89:19)<br> &nbsp; &nbsp;at /home/runner/work/graphql-http/graphql-http/node_modules/body-parser/lib/read.js:128:18<br> &nbsp; &nbsp;at AsyncResource.runInAsyncScope (node:async_hooks:203:9)<br> &nbsp; &nbsp;at invokeCallback (/home/runner/work/graphql-http/graphql-http/node_modules/raw-body/index.js:231:16)<br> &nbsp; &nbsp;at done (/home/runner/work/graphql-http/graphql-http/node_modules/raw-body/index.js:220:7)<br> &nbsp; &nbsp;at IncomingMessage.onEnd (/home/runner/work/graphql-http/graphql-http/node_modules/raw-body/index.js:280:7)<br> &nbsp; &nbsp;at IncomingMessage.emit (node:events:513:28)<br> &nbsp; &nbsp;at endReadableNT (node:internal/streams/rea...
199196
```

implementations/thegraph/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Status code 404 is not 200
3232
```
3333
4. MAY NOT allow executing mutations on GET requests<br />
3434
```
35-
Status code 200 is not 405
35+
Status code 200 is not greater than or equal to 400
3636
```
3737
5. SHOULD use 400 status code on missing {query} parameter when accepting application/graphql-response+json<br />
3838
```

src/audits/server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ export function serverAudits(opts: ServerAuditOptions): Audit[] {
211211
accept: 'application/graphql-response+json',
212212
},
213213
});
214-
assert('Status code', res.status).toBe(405);
214+
assert('Status code', res.status).toBeGreaterThanOrEqual(400);
215+
assert('Status code', res.status).toBeLessThanOrEqual(499);
215216
}),
216217
// Request POST
217218
audit(

0 commit comments

Comments
 (0)