Skip to content
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

add asn support #55

Closed
wants to merge 1 commit into from
Closed

add asn support #55

wants to merge 1 commit into from

Conversation

dogancanbakir
Copy link
Member

Closes #54

@dogancanbakir dogancanbakir self-assigned this Jan 8, 2024
Copy link
Member

@Mzack9999 Mzack9999 left a comment

Choose a reason for hiding this comment

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

I was a bit unsure about merging this functionality as there is an intrinsic circular loop: mapcidr->asnmap->networkpolicy (in this PR ->mapcidr).
I confirm it works with both httpx and nuclei.
Probably the safest approach would be to make a little copy of the following:

func expandCIDRInputValue(value string) []string {
	var ips []string
	ipsCh, _ := mapcidr.IPAddressesAsStream(value)
	for ip := range ipsCh {
		ips = append(ips, ip)
	}
	return ips
}

func expandASNInputValue(value string) []string {
	var ips []string
	cidrs, _ := asn.GetCIDRsForASNNum(value)
	for _, cidr := range cidrs {
		ips = append(ips, expandCIDRInputValue(cidr.String())...)
	}
	return ips
}

...
case asn.IsASN(exclude):
ips := expandASNInputValue(exclude)
options.Deny = append(options.Deny, ips...)
...

Quoting:

A little copying is better than a little dependency

What do you think?

@dogancanbakir
Copy link
Member Author

I am not satisfied with the current dependency tree that we have created. Rather than copying a large amount of code from mapcidr, we can move some parts to the utils to avoid this. I am not entirely certain if this approach is feasible or the right one, but it seems like the only solution that makes sense to me 💭.

@dogancanbakir
Copy link
Member Author

Closing this. Will revisit the issue.

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.

Add ASN support to Allow/Deny
2 participants