Skip to content

fix: validate header names/values and prevent CRLF injection (#1817) - #2442

Open
SaumyaT-21 wants to merge 6 commits into
utksh1:mainfrom
SaumyaT-21:fix/44-crawler-header-validation
Open

fix: validate header names/values and prevent CRLF injection (#1817)#2442
SaumyaT-21 wants to merge 6 commits into
utksh1:mainfrom
SaumyaT-21:fix/44-crawler-header-validation

Conversation

@SaumyaT-21

Copy link
Copy Markdown
Collaborator

Description

Validates HTTP header names and values in crawler.py to ensure they conform to HTTP specs.
Specifically:

  • Enforces header name and value validation against expected HTTP token grammar.
  • Checks for and rejects \r (Carriage Return) and \n (Line Feed) characters to prevent header injection (CRLF) vulnerabilities.
  • Raises a ValueError with clear messaging when an invalid header format or illegal character is detected.

Related Issues

Closes #1817

Type of Change

  • [x] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

How Has This Been Tested?

Tested manually via a local test block in crawler.py using Python in the project's virtual environment:

  1. Valid Headers Test: Verified compliant header keys and values execute cleanly without errors.
  2. CRLF Injection Tests: Verified that passing \r or \n characters in either the header name or the header value correctly raises a ValueError.

Checklist

  • [x] My code follows the code style of this project.
  • [x] I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • [x] My changes generate no new warnings.

@SaumyaT-21

Copy link
Copy Markdown
Collaborator Author

Hey @utksh1 ! Added the fix for CRLF injection and HTTP token validation. All green on CI checks. Please go ahead and review the changes!

@utksh1 utksh1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes: _HEADER_NAME_re.match() is not anchored, so a value such as X-Test@invalid can pass by matching only the valid prefix. Use a full match/anchors and add tests for trailing invalid characters. Also remove the unrelated frontend/package-lock.json update and add coverage for invalid field values through the actual header-building path.

@utksh1 utksh1 added area:backend Backend API, database, or service work level:intermediate 35 pts difficulty label for moderate contributor PRs type:security Security work category bonus label labels Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend Backend API, database, or service work level:intermediate 35 pts difficulty label for moderate contributor PRs type:security Security work category bonus label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[#44] crawler injects extra-header values unsanitized

2 participants