-
Notifications
You must be signed in to change notification settings - Fork 0
fix(ci): pin GitHub-hosted Ubuntu runner image #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aa54807
test(ci): require explicit hosted runner image
seonghobae 2770b57
fix(ci): pin hosted Ubuntu runner
seonghobae 33ebae0
fix(ci): pin fuzz runner image
seonghobae 2d41c40
fix(ci): pin scorecard runner image
seonghobae ced58fe
feat(gateway): trust forwarded IPs only from trusted proxies (#131)
seonghobae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| #![no_main] | ||
| //! Fuzz trusted client-IP attribution for forwarded proxy headers. | ||
| //! | ||
| //! `effective_client_ip` is a trust-boundary parser: it decides whether | ||
| //! attacker-controlled forwarding headers can influence rate limiting, DNSBL | ||
| //! checks, and audit/event attribution. Arbitrary chains, invalid hops, IPv4, | ||
| //! IPv6, trusted peers, and untrusted peers must never panic, and the trusted | ||
| //! peer path must match the documented right-to-left selection rule. | ||
|
|
||
| use arbitrary::Arbitrary; | ||
| use libfuzzer_sys::fuzz_target; | ||
| use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; | ||
| use waf_ids_ai_soc::{IpNet, effective_client_ip}; | ||
|
|
||
| #[derive(Arbitrary, Debug, Clone)] | ||
| enum AnyIp { | ||
| V4(u32), | ||
| V6(u128), | ||
| } | ||
|
|
||
| impl AnyIp { | ||
| fn into_ip(self) -> IpAddr { | ||
| match self { | ||
| Self::V4(raw) => IpAddr::V4(Ipv4Addr::from(raw)), | ||
| Self::V6(raw) => IpAddr::V6(Ipv6Addr::from(raw)), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn normalized_ip(addr: IpAddr) -> IpAddr { | ||
| match addr { | ||
| IpAddr::V6(ip) => ip | ||
| .to_ipv4_mapped() | ||
| .map(IpAddr::V4) | ||
| .unwrap_or(IpAddr::V6(ip)), | ||
| IpAddr::V4(ip) => IpAddr::V4(ip), | ||
| } | ||
| } | ||
|
|
||
| fn is_trusted_single_host(ip: IpAddr, trusted_proxy_ip: IpAddr) -> bool { | ||
| normalized_ip(ip) == normalized_ip(trusted_proxy_ip) | ||
| } | ||
|
|
||
| #[derive(Arbitrary, Debug)] | ||
| enum Hop { | ||
| Ip(AnyIp), | ||
| Invalid(String), | ||
| Empty, | ||
| } | ||
|
|
||
| impl Hop { | ||
| fn into_text(self) -> String { | ||
| match self { | ||
| Self::Ip(ip) => ip.into_ip().to_string(), | ||
| Self::Invalid(raw) => raw, | ||
| Self::Empty => " ".to_string(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Arbitrary, Debug)] | ||
| struct Input { | ||
| trusted_proxy: AnyIp, | ||
| peer_ip: Option<AnyIp>, | ||
| trust_peer: bool, | ||
| forwarded_hops: Vec<Hop>, | ||
| x_real_ip: Option<Hop>, | ||
| } | ||
|
|
||
| fn expected_client_ip( | ||
| peer_ip: Option<IpAddr>, | ||
| x_forwarded_for: Option<&str>, | ||
| x_real_ip: Option<&str>, | ||
| trusted_proxy_ip: IpAddr, | ||
| trust_peer: bool, | ||
| ) -> Option<IpAddr> { | ||
| let peer_ip = match (peer_ip, trust_peer) { | ||
| (Some(_), false) => peer_ip, | ||
| (Some(peer_ip), true) => Some(peer_ip), | ||
| (None, _) => return None, | ||
| }?; | ||
|
|
||
| if !trust_peer { | ||
| return Some(peer_ip); | ||
| } | ||
|
|
||
| if let Some(forwarded) = x_forwarded_for { | ||
| for hop in forwarded.split(',').rev() { | ||
| let hop = hop.trim(); | ||
| if hop.is_empty() { | ||
| continue; | ||
| } | ||
| let Ok(ip) = hop.parse::<IpAddr>() else { | ||
| continue; | ||
| }; | ||
| if is_trusted_single_host(ip, trusted_proxy_ip) { | ||
| continue; | ||
| } | ||
| return Some(ip); | ||
| } | ||
| } | ||
|
|
||
| x_real_ip | ||
| .and_then(|value| value.trim().parse::<IpAddr>().ok()) | ||
| .or(Some(peer_ip)) | ||
| } | ||
|
|
||
| fuzz_target!(|input: Input| { | ||
| let trusted_proxy_ip = input.trusted_proxy.clone().into_ip(); | ||
| let peer_ip = input.peer_ip.map(AnyIp::into_ip); | ||
| let trusted_cidr = match trusted_proxy_ip { | ||
| IpAddr::V4(ip) => format!("{ip}/32"), | ||
| IpAddr::V6(ip) => format!("{ip}/128"), | ||
| }; | ||
| let trusted_proxy = IpNet::parse(&trusted_cidr).expect("single-host CIDR must parse"); | ||
| let trusted_proxies = vec![trusted_proxy.clone()]; | ||
| let peer_ip = if input.trust_peer && peer_ip.is_some() { | ||
| Some(trusted_proxy_ip) | ||
| } else { | ||
| peer_ip | ||
| }; | ||
| let trust_peer = peer_ip | ||
| .map(|peer_ip| is_trusted_single_host(peer_ip, trusted_proxy_ip)) | ||
| .unwrap_or(false); | ||
| let x_forwarded_for = if input.forwarded_hops.is_empty() { | ||
| None | ||
| } else { | ||
| Some( | ||
| input | ||
| .forwarded_hops | ||
| .into_iter() | ||
| .map(Hop::into_text) | ||
| .collect::<Vec<_>>() | ||
| .join(","), | ||
| ) | ||
| }; | ||
| let x_real_ip = input.x_real_ip.map(Hop::into_text); | ||
| let resolved = effective_client_ip(peer_ip, x_forwarded_for.as_deref(), x_real_ip.as_deref(), &trusted_proxies); | ||
| let expected = expected_client_ip( | ||
| peer_ip, | ||
| x_forwarded_for.as_deref(), | ||
| x_real_ip.as_deref(), | ||
| trusted_proxy_ip, | ||
| trust_peer, | ||
| ); | ||
| assert_eq!( | ||
| resolved, expected, | ||
| "trusted client attribution must match the right-to-left trust model" | ||
| ); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔍 New fuzz target lacks documentation
The fuzzing target table omits
fuzz_trusted_forwarded_client_ipand its invariant. Repository guidance says this document lists each target's invariants.Was this helpful? React with 👍 or 👎 to provide feedback.