security: improve IPv4 packet validation#344
Open
hongkongkiwi wants to merge 4 commits intoexpressvpn:mainfrom
Open
security: improve IPv4 packet validation#344hongkongkiwi wants to merge 4 commits intoexpressvpn:mainfrom
hongkongkiwi wants to merge 4 commits intoexpressvpn:mainfrom
Conversation
Add comprehensive validation for incoming IPv4 packets: - Check minimum packet size (20 bytes header) - Validate IP version is 4 - Validate header length field (IHL) is at least 5 and doesn't exceed packet size - Validate total length field is reasonable - Skip loopback (127.x.x.x) and reserved (0.x.x.x) source/destination addresses These checks prevent various packet-based attacks including: - Truncated packet attacks - Invalid header length attacks - Loopback/reserved address spoofing Also adds test cases for the new validation logic.
Reject packets with destination 255.255.255.255 to prevent potential broadcast storms or abuse. This is in addition to the existing checks for loopback (127.x.x.x) and reserved (0.x.x.x) addresses.
Add documentation noting that production deployments should consider lowering the default max entries (65535) to limit memory consumption from fragmented packet attacks.
- Fix v6_not_supported test case to use 24-byte buffer starting with 0x60 (previously only 1 byte, which tested minimum size instead of version check) - Fix test packet total_length byte order (was 0x1c, 0x00 -> now 0x00, 0x1c) - Add docstring to ipv4_is_valid_packet function to improve coverage
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
Enhanced IPv4 packet validation with comprehensive security checks:
Changes
Files Changed
lightway-core/src/utils.rs: Enhancedipv4_is_valid_packet()functionSecurity Impact
Prevents various packet-based attacks: