Skip to content

Fix raw HTTP parser panic on single-LF request body - #7525

Merged
dwisiswant0 merged 1 commit into
projectdiscovery:devfrom
zainnadeem786:fix-7524-raw-http-lf-body
Jul 17, 2026
Merged

Fix raw HTTP parser panic on single-LF request body#7525
dwisiswant0 merged 1 commit into
projectdiscovery:devfrom
zainnadeem786:fix-7524-raw-http-lf-body

Conversation

@zainnadeem786

@zainnadeem786 zainnadeem786 commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes a panic in the raw HTTP request parser when the request body is empty or contains only newline characters.

ParseRawRequest trimmed a trailing newline and then immediately accessed the final byte again. For a body containing only "\n", the first trim left an empty slice and the next access could panic with:

panic: runtime error: index out of range [-1]

Changes

  • Add length guards around raw request body trailing-newline trimming.

  • Preserve the existing parsing behavior for normal bodies.

  • Add regression coverage for:

    • "\n"
    • "\r\n"
    • ""
    • "A\n"
  • Cover both ParseRawRequest and ParseRawRequestWithURL.

Tests

go test ./pkg/input/types

Closes #7524.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of request bodies with trailing newline characters, including empty bodies, to prevent crashes and ensure parsing succeeds.
    • Request parsing now trims ending line breaks more reliably, returning the expected body content in edge cases.
  • Tests
    • Added coverage for raw HTTP request parsing with different trailing newline and empty-body scenarios.

@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 16abcec9-9de8-4574-8137-5be3754552b0

📥 Commits

Reviewing files that changed from the base of the PR and between e4a83ad and 9847e14.

📒 Files selected for processing (2)
  • pkg/input/types/http.go
  • pkg/input/types/http_test.go

Walkthrough

The request-body trailing newline trimming logic in ParseRawRequest was updated to check that the byte slice is non-empty before indexing its last byte, preventing an index-out-of-range panic. A new test verifies parsing behavior for bodies with empty, LF-only, and CRLF-only trailing content.

Changes

Raw request body trim panic fix

Layer / File(s) Summary
Guard trailing newline trimming and regression test
pkg/input/types/http.go, pkg/input/types/http_test.go
Adds len(bin) > 0 checks before trimming trailing \n/\r bytes to avoid indexing an empty slice, and adds a test exercising empty, LF-only, and CRLF-only body cases via ParseRawRequest and ParseRawRequestWithURL.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Poem

A single \n once made me quake,
Index out of range — a rookie mistake!
Now I check my length before I trim,
No more panics, no more grim.
Hop hop hooray, the bug's undone! 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing a raw HTTP parser panic on single-LF bodies.
Linked Issues check ✅ Passed The fix addresses #7524 by preventing the raw parser panic on empty/newline-only bodies and adds regression tests for both parsing paths.
Out of Scope Changes check ✅ Passed The changes are confined to the parser guard and focused regression tests, with no unrelated scope added.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@zainnadeem786

Copy link
Copy Markdown
Contributor Author

The functional test failures appear unrelated to this PR. The jobs fail while projectdiscovery/nuclei-action@v3 is downloading the latest Nuclei binary:

Error: Could not download nuclei: Unexpected HTTP response: 404

This happens before the functional tests execute, across macOS, Ubuntu, and Windows. Please let me know if you would like me to re-run the checks once the action/download issue is resolved.

@dwisiswant0
dwisiswant0 merged commit 0888e62 into projectdiscovery:dev Jul 17, 2026
31 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Raw HTTP parser panics when request body consists of a single LF character

2 participants