fix(http): harden HTTP layer — 18 bugs fixed#23
Merged
Conversation
Bugs fixed (grade-0 risks): - execute.cpp: getcwd() NULL dereference → UB/crash - execute.cpp: SIGPIPE not ignored → server crash when CGI closes stdin early - output.cpp: usesDoubleCRLF detection inverted → \r\n prepended to every CGI body Bugs fixed (evaluation failures): - GetHandler: read() error silently served as 200 OK → now returns 500 - GetHandler/DeleteHandler: EACCES returns 404 → now returns 403 - GetHandler: filter . and .. from autoindex listing - GetHandler: fallback to autoindex when index file is missing - MethodHandler: 301 redirect missing Content-Length header - MethodHandler: add applyCustomErrorPage() for error_page config support - PostHandler: open() error always 403 → distinguish EACCES vs ENOENT (500) - Router: query string in URI breaks location matching - GetHandler/DeleteHandler/PostHandler: query string appended to file paths → 404 - execute.cpp: waitpid(WNOHANG, NULL) reaps child, loses exit status - Router: normalize trailing slash on location paths Compliance fixes: - ResponseBuilder: add RFC 7231 mandatory Date header - ResponseBuilder: add Connection: close to prevent hanging connections - StringUtils: hasPathTraversal too broad — only block full path segments - HttpResponse: initialize status_code=0 to avoid UB Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
getcwd()NULL deref, SIGPIPE server crash, CGI body offset bug (usesDoubleCRLF inverted)./..links, missingerror_pagesupport, index fallback, Connection header, Date headerread()error handling,waitpidexit status, path traversal precision, trailing slash routing,status_codeUBFiles changed
src/http/cgi/output.cppusesDoubleCRLFdetection (body offset +2 vs +4)src/http/cgi/execute.cppgetcwdNULL,SIGPIPEignore, remove buggyWNOHANGwaitpidsrc/http/handlers/GetHandler.cppread()error → 500,EACCES→ 403, filter./..autoindex, index fallback, strip query stringsrc/http/handlers/DeleteHandler.cppEACCES→ 403, strip query stringsrc/http/handlers/PostHandler.cppopen()errno distinction, strip query string from filenamesrc/http/handlers/MethodHandler.cppConnection: close, custom error pages (applyCustomErrorPage), 301Content-Lengthsrc/http/response/ResponseBuilder.cppDateheader,Connection: closesrc/http/router/Router.cppsrc/http/utils/StringUtils.cpphasPathTraversal— only block full path segments (/../), not filenames with..include/http/HttpResponse.hppstatus_code = 0(UB fix)Constraint check (grade-0)
poll()— no new call sites added ✅errno— only checked afteropen()andstat(), never afterread/write/recv/send✅fork()— unchanged, CGI only ✅fcntl()— onlyF_SETFL/O_NONBLOCK(pre-existing) ✅Test plan
GET /file.html?v=2— serves file (not 404)GET /dir/with autoindex — no.or..entriesGET /dir/with missing index + autoindex ON — shows listing (not 404)\r\n\r\nseparator — body correct (no leading\r\n)curl -vany response —Date:andConnection: closepresenterror_page 404 /errors/404.htmlin config — custom page served on 404Made with Cursor