Skip to content

fix(runner): preserve last header in raw request files without trailing newline - #2661

Merged
Mzack9999 merged 4 commits into
projectdiscovery:devfrom
AdamMagued:fix-issue-2657
Oct 10, 2026
Merged

Mzack9999 merged 4 commits into
projectdiscovery:devfrom
AdamMagued:fix-issue-2657

Conversation

@AdamMagued

@AdamMagued AdamMagued commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2657

Summary

  • Prevented raw request header truncation when trailing newline is omitted
  • Added unit tests validating headers parsing with and without trailing newline

Verified in container sandbox.

Summary by CodeRabbit

  • Bug Fixes
    • Raw HTTP requests without a trailing newline are now parsed correctly, including their headers and request line.
    • Automatic HTTP/HTTPS detection now retries over HTTPS after receiving a plaintext HTTP 400 response. If the HTTPS attempt fails, the original response is preserved.
    • Request parsing now handles a final header line without a trailing newline. Safe mode continues to exclude Content-Length headers, while unsafe mode preserves header lines without a colon.

ehsandeep and others added 2 commits September 8, 2026 19:05
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 020f81ac-2b15-463f-9487-14468b5e6916

📥 Commits

Reviewing files that changed from the base of the PR and between 7d242a2 and 303bacc.


📒 Files selected for processing (1)
  • runner/runner_test.go

 __________________________________________
< Performing energy-intensive code review. >
 ------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 73d5791b-7579-4bdd-b996-4219b5c8fa4f

📥 Commits

Reviewing files that changed from the base of the PR and between 10b2453 and 7d242a2.


📒 Files selected for processing (4)
  • common/httputilz/httputilz.go
  • common/httputilz/httputilz_test.go
  • runner/runner.go
  • runner/runner_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.



Walkthrough

ParseRequest now processes nonblank final request and header lines returned with EOF. Runner initialization retains headers from raw requests without trailing newlines. Automatic scheme detection retries over HTTPS after an HTTP 400 response, except in unsafe mode.

Changes

Raw request parsing

Layer / File(s) Summary
Parse final request lines
common/httputilz/httputilz.go, common/httputilz/httputilz_test.go
ParseRequest accepts a nonempty request line at EOF and processes a nonblank final header before stopping. Tests cover CRLF and LF input, safe and unsafe header handling, and requests without headers.
Load parsed raw-request headers
runner/runner.go, runner/runner_test.go
Raw-request parse failures now report the parser error. A runner test checks that API key and host headers from a request without a trailing newline appear in CustomHeaders.

Automatic HTTPS retry

Layer / File(s) Summary
Retry HTTP 400 responses over HTTPS
runner/runner.go
During automatic scheme detection, Runner saves an HTTP 400 result and retries over HTTPS unless unsafe mode is enabled. If the retry fails, Runner restores the saved plaintext result.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant Runner as Runner.analyze
  participant HTTP as HTTP target
  participant HTTPS as HTTPS target
  Runner->>HTTP: Send request during automatic detection
  HTTP-->>Runner: Return HTTP 400
  Runner->>HTTPS: Retry request unless unsafe mode is enabled
  HTTPS-->>Runner: Return response or failure
  Runner->>Runner: Restore saved HTTP result if HTTPS fails
Loading

Suggested reviewers: mzack9999

Merge Risk: ⚪ Minimal · up to 7d242

No actionable risk introduced by this PR was established; the reviewed changes are mergeable subject to normal checks.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: preserving the final header in raw request files without a trailing newline.
Linked Issues check Passed Issue #2657 requires -rr to preserve the final header without a trailing newline for CRLF, LF, and unsafe parsing. ParseRequest now processes nonblank text returned with a read error before it exi…
Out of Scope Changes check Passed The changes stay within issue #2657. The parser change and parser tests implement and verify final-header preservation. The runner test verifies raw-request loading. The runner.go change reports the…

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks each request line,
And saves the header at the end.
No newline hides its value now,
HTTP 400 gets one more try,
Then HTTPS replies—or old results return.

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

@Mzack9999
Mzack9999 merged commit 05d988f into projectdiscovery:dev Oct 10, 2026
12 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.

-rr drops the last header when the raw request file has no trailing newline

3 participants