Skip to content

Commit 8cd7dfb

Browse files
fix(audits/server): Prefer using POST (#77)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 365f9f0 commit 8cd7dfb

File tree

5 files changed

+17
-73
lines changed

5 files changed

+17
-73
lines changed

implementations/apollo-server/README.md

+3-40
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44

55
<ul>
66
<li><b>37</b> audits in total</li>
7-
<li><span style="font-family: monospace">✅</span> <b>30</b> pass</li>
8-
<li><span style="font-family: monospace">⚠️</span> <b>7</b> warnings (optional)</li>
7+
<li><span style="font-family: monospace">✅</span> <b>31</b> pass</li>
8+
<li><span style="font-family: monospace">⚠️</span> <b>6</b> warnings (optional)</li>
99
</ul>
1010

1111
<h2>Passing</h2>
1212
<ol>
1313
<li><code>22EB</code> SHOULD accept application/graphql-response+json and match the content-type</li>
1414
<li><code>4655</code> MUST accept application/json and match the content-type</li>
1515
<li><code>47DE</code> SHOULD accept */* and use application/json for the content-type</li>
16+
<li><code>80D8</code> SHOULD assume application/json content-type when accept is missing</li>
1617
<li><code>82A3</code> MUST use utf-8 encoding when responding</li>
1718
<li><code>BF61</code> MUST accept utf-8 encoded request</li>
1819
<li><code>78D5</code> MUST assume utf-8 in request if encoding is unspecified</li>
@@ -45,44 +46,6 @@
4546
<h2>Warnings</h2>
4647
The server <i>SHOULD</i> support these, but is not required.
4748
<ol>
48-
<li><code>80D8</code> SHOULD assume application/json content-type when accept is missing
49-
<details>
50-
<summary>Response status code is not 200</summary>
51-
<pre><code class="lang-json">{
52-
"statusText": "Bad Request",
53-
"status": 400,
54-
"headers": {
55-
"x-powered-by": "Express",
56-
"etag": "W/\"5b5-gDRXf8j0lbjWbmQpeY60iENT2cI\"",
57-
"date": "<timestamp>",
58-
"content-type": "application/json; charset=utf-8",
59-
"content-length": "1461",
60-
"connection": "close",
61-
"access-control-allow-origin": "*"
62-
},
63-
"body": {
64-
"errors": [
65-
{
66-
"message": "This operation has been blocked as a potential Cross-Site Request Forgery (CSRF). Please either specify a 'content-type' header (with a type that is not one of application/x-www-form-urlencoded, multipart/form-data, text/plain) or provide a non-empty value for one of the following headers: x-apollo-operation-name, apollo-require-preflight\n",
67-
"extensions": {
68-
"stacktrace": [
69-
"BadRequestError: This operation has been blocked as a potential Cross-Site Request Forgery (CSRF). Please either specify a 'content-type' header (with a type that is not one of application/x-www-form-urlencoded, multipart/form-data, text/plain) or provide a non-empty value for one of the following headers: x-apollo-operation-name, apollo-require-preflight",
70-
"",
71-
" at new GraphQLErrorWithCode (file:///home/runner/work/graphql-http/graphql-http/node_modules/@apollo/server/dist/esm/internalErrorClasses.js:7:9)",
72-
" at new BadRequestError (file:///home/runner/work/graphql-http/graphql-http/node_modules/@apollo/server/dist/esm/internalErrorClasses.js:75:9)",
73-
" at preventCsrf (file:///home/runner/work/graphql-http/graphql-http/node_modules/@apollo/server/dist/esm/preventCsrf.js:29:11)",
74-
" at ApolloServer.executeHTTPGraphQLRequest (file:///home/runner/work/graphql-http/graphql-http/node_modules/@apollo/server/dist/esm/ApolloServer.js:478:17)",
75-
" at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"
76-
],
77-
"code": "BAD_REQUEST"
78-
}
79-
}
80-
]
81-
}
82-
}
83-
</code></pre>
84-
</details>
85-
</li>
8649
<li><code>5A70</code> MAY accept application/x-www-form-urlencoded formatted GET requests
8750
<details>
8851
<summary>Response status code is not 200</summary>
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"total": 37,
3-
"ok": 30,
4-
"warn": 7,
3+
"ok": 31,
4+
"warn": 6,
55
"error": 0
66
}

implementations/postgraphile/README.md

+3-26
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55
<ul>
66
<li><b>37</b> audits in total</li>
7-
<li><span style="font-family: monospace">✅</span> <b>29</b> pass</li>
8-
<li><span style="font-family: monospace">⚠️</span> <b>8</b> warnings (optional)</li>
7+
<li><span style="font-family: monospace">✅</span> <b>30</b> pass</li>
8+
<li><span style="font-family: monospace">⚠️</span> <b>7</b> warnings (optional)</li>
99
</ul>
1010

1111
<h2>Passing</h2>
1212
<ol>
1313
<li><code>4655</code> MUST accept application/json and match the content-type</li>
1414
<li><code>47DE</code> SHOULD accept */* and use application/json for the content-type</li>
15+
<li><code>80D8</code> SHOULD assume application/json content-type when accept is missing</li>
1516
<li><code>82A3</code> MUST use utf-8 encoding when responding</li>
1617
<li><code>BF61</code> MUST accept utf-8 encoded request</li>
1718
<li><code>78D5</code> MUST assume utf-8 in request if encoding is unspecified</li>
@@ -65,30 +66,6 @@ The server <i>SHOULD</i> support these, but is not required.
6566
</code></pre>
6667
</details>
6768
</li>
68-
<li><code>80D8</code> SHOULD assume application/json content-type when accept is missing
69-
<details>
70-
<summary>Response status code is not 200</summary>
71-
<pre><code class="lang-json">{
72-
"statusText": "Method Not Allowed",
73-
"status": 405,
74-
"headers": {
75-
"date": "<timestamp>",
76-
"content-type": "application/json; charset=utf-8",
77-
"content-length": "60",
78-
"connection": "close",
79-
"allow": "POST, OPTIONS"
80-
},
81-
"body": {
82-
"errors": [
83-
{
84-
"message": "Only `POST` requests are allowed."
85-
}
86-
]
87-
}
88-
}
89-
</code></pre>
90-
</details>
91-
</li>
9269
<li><code>5A70</code> MAY accept application/x-www-form-urlencoded formatted GET requests
9370
<details>
9471
<summary>Response status code is not 200</summary>
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"total": 37,
3-
"ok": 29,
4-
"warn": 8,
3+
"ok": 30,
4+
"warn": 7,
55
"error": 0
66
}

src/audits/server.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,14 @@ export function serverAudits(opts: ServerAuditOptions): Audit[] {
9494
'80D8',
9595
'SHOULD assume application/json content-type when accept is missing',
9696
async () => {
97-
const url = new URL(await getUrl(opts.url));
98-
url.searchParams.set('query', '{ __typename }');
97+
const res = await fetchFn(await getUrl(opts.url), {
98+
method: 'POST',
99+
headers: {
100+
'content-type': 'application/json',
101+
},
102+
body: JSON.stringify({ query: '{ __typename }' }),
103+
});
99104

100-
const res = await fetchFn(url.toString());
101105
ressert(res).status.toBe(200);
102106
ressert(res).header('content-type').toContain('application/json');
103107
},

0 commit comments

Comments
 (0)