Skip to content

Commit af2c8f7

Browse files
committed
Add fetch metadata request headers
Adds the standard fetch metadata request headers (sec-fetch-xxx) to the krequ lookup map. Also adds a regression test for this.
1 parent fba4bc3 commit af2c8f7

File tree

5 files changed

+97
-2
lines changed

5 files changed

+97
-2
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ REGRESS = regress/test-abort-validator \
232232
regress/test-fcgi-ping \
233233
regress/test-fcgi-ping-double \
234234
regress/test-fcgi-upload \
235+
regress/test-fetch-metadata-request \
235236
regress/test-file-get \
236237
regress/test-fork \
237238
regress/test-gzip \

child.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ static const char *const krequs[KREQU__MAX] = {
184184
"HTTP_PROXY_AUTHORIZATION", /* KREQU_PROXY_AUTHORIZATION */
185185
"HTTP_RANGE", /* KREQU_RANGE */
186186
"HTTP_REFERER", /* KREQU_REFERER */
187+
"HTTP_SEC_FETCH_DEST", /* KREQU_SEC_FETCH_DEST */
188+
"HTTP_SEC_FETCH_MODE", /* KREQU_SEC_FETCH_MODE */
189+
"HTTP_SEC_FETCH_USER", /* KREQU_SEC_FETCH_USER */
190+
"HTTP_SEC_FETCH_SITE", /* KREQU_SEC_FETCH_SITE */
187191
"HTTP_USER_AGENT", /* KREQU_USER_AGENT */
188192
};
189193

kcgi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ enum krequ {
155155
KREQU_PROXY_AUTHORIZATION,
156156
KREQU_RANGE,
157157
KREQU_REFERER,
158+
KREQU_SEC_FETCH_DEST,
159+
KREQU_SEC_FETCH_MODE,
160+
KREQU_SEC_FETCH_USER,
161+
KREQU_SEC_FETCH_SITE,
158162
KREQU_USER_AGENT,
159163
KREQU__MAX
160164
};

man/kcgi.3

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ and the
337337
version 1.0, published 29 April 1996.
338338
.Bl -bullet
339339
.It
340+
Metadata request headers are specified by
341+
.Lk https://w3c.github.io/webappsec-fetch-metadata "Fetch Metadata Request Headers" .
342+
.It
340343
Cookies are parsed according to
341344
.Dq HTTP State Management Mechanism ,
342345
RFC 6265.
@@ -376,12 +379,12 @@ HTTP dates (logging and date-time management) are specified by
376379
.It
377380
URL encoding and decoding is defined by RFC 3986,
378381
.Dq Uniform Resource Identifier (URI): Generic Syntax .
379-
.El
380-
.Pp
382+
.It
381383
Additional HTTP methods are defined by RFC 4918,
382384
.Dq HTTP Extensions for Web Distributed Authoring and Versioning ;
383385
and RFC 4791 ,
384386
.Dq Calendaring Extensions to WebDAV .
387+
.El
385388
.Sh AUTHORS
386389
The
387390
.Nm
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright (c) Kristaps Dzonsons <kristaps@bsd.lv>
3+
*
4+
* Permission to use, copy, modify, and distribute this software for any
5+
* purpose with or without fee is hereby granted, provided that the above
6+
* copyright notice and this permission notice appear in all copies.
7+
*
8+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15+
*/
16+
#include "../config.h"
17+
18+
#include <stdarg.h>
19+
#include <stdint.h>
20+
#include <stdlib.h>
21+
#include <string.h>
22+
#include <unistd.h>
23+
24+
#include <curl/curl.h>
25+
26+
#include "../kcgi.h"
27+
#include "regress.h"
28+
29+
static int
30+
parent(CURL *curl)
31+
{
32+
struct curl_slist *slist;
33+
int ret;
34+
35+
slist = NULL;
36+
slist = curl_slist_append(slist, "Sec-Fetch-Dest: www.example.com");
37+
slist = curl_slist_append(slist, "Sec-Fetch-User: ?1");
38+
slist = curl_slist_append(slist, "Sec-Fetch-Mode: navigate");
39+
slist = curl_slist_append(slist, "Sec-Fetch-Site: same-origin");
40+
curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:17123/");
41+
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
42+
ret = curl_easy_perform(curl);
43+
curl_slist_free_all(slist);
44+
return(CURLE_OK == ret);
45+
}
46+
47+
static int
48+
child(void)
49+
{
50+
struct kreq r;
51+
const char *page = "index";
52+
53+
if (khttp_parse(&r, NULL, 0, &page, 1, 0) != KCGI_OK)
54+
return 0;
55+
56+
if (r.reqmap[KREQU_SEC_FETCH_DEST] == NULL ||
57+
strcmp(r.reqmap[KREQU_SEC_FETCH_DEST]->val, "www.example.com") != 0)
58+
return 0;
59+
if (r.reqmap[KREQU_SEC_FETCH_USER] == NULL ||
60+
strcmp(r.reqmap[KREQU_SEC_FETCH_USER]->val, "?1") != 0)
61+
return 0;
62+
if (r.reqmap[KREQU_SEC_FETCH_MODE] == NULL ||
63+
strcmp(r.reqmap[KREQU_SEC_FETCH_MODE]->val, "navigate") != 0)
64+
return 0;
65+
if (r.reqmap[KREQU_SEC_FETCH_SITE] == NULL ||
66+
strcmp(r.reqmap[KREQU_SEC_FETCH_SITE]->val, "same-origin") != 0)
67+
return 0;
68+
69+
khttp_head(&r, kresps[KRESP_STATUS],
70+
"%s", khttps[KHTTP_200]);
71+
khttp_head(&r, kresps[KRESP_CONTENT_TYPE],
72+
"%s", kmimetypes[KMIME_TEXT_HTML]);
73+
khttp_body(&r);
74+
khttp_free(&r);
75+
return 1;
76+
}
77+
78+
int
79+
main(int argc, char *argv[])
80+
{
81+
82+
return(regress_cgi(parent, child) ? EXIT_SUCCESS : EXIT_FAILURE);
83+
}

0 commit comments

Comments
 (0)