wired
libc-free QUIC/HTTP3 SDK in C for x86_64-linux
Loading...
Searching...
No Matches
staticfile.h File Reference

Resolve an HTTP request path into a document-root-relative file path for static file serving (quiche-server's –root/–index), rejecting path traversal. More...

Go to the source code of this file.

Functions

int wired_staticfile_has_traversal (const char *path)
 1 if path contains a ".." path-traversal segment: "/../", a leading "../", or a trailing "/..".
int wired_staticfile_resolve (const char *root, const char *reqpath, const char *index, char *out, usz outcap)
 Resolve reqpath against root into out, rejecting traversal.

Detailed Description

Resolve an HTTP request path into a document-root-relative file path for static file serving (quiche-server's –root/–index), rejecting path traversal.

Socket- and filesystem-free: string manipulation only, the caller opens the resolved path (e.g. via wired_fio_read).

Function Documentation

◆ wired_staticfile_has_traversal()

int wired_staticfile_has_traversal ( const char * path)

1 if path contains a ".." path-traversal segment: "/../", a leading "../", or a trailing "/..".

A ".." that is merely a substring of a longer segment (e.g. "foo..bar.txt") is NOT flagged.

Parameters
pathNUL-terminated request path
Returns
1 if a ".." segment is present, 0 otherwise

◆ wired_staticfile_resolve()

int wired_staticfile_resolve ( const char * root,
const char * reqpath,
const char * index,
char * out,
usz outcap )

Resolve reqpath against root into out, rejecting traversal.

root is always prefixed (no absolute-path double interpretation). If reqpath is empty or ends in "/", index is appended as the file name (e.g. root="/www", reqpath="/", index="index.html" -> "/www/index.html").

Parameters
rootNUL-terminated document root, no trailing slash
reqpathNUL-terminated request path, e.g. "/foo/bar.txt"
indexNUL-terminated index file name used when reqpath names a directory (empty or trailing "/")
outdestination buffer for the resolved, NUL-terminated path
outcapcapacity of out in bytes, including the NUL terminator
Returns
1 on success; 0 if reqpath contains a ".." segment or the resolved path (with NUL) does not fit in outcap