Skip to content

Conversation

@bitterpanda63
Copy link
Member

@bitterpanda63 bitterpanda63 commented Dec 8, 2025

Summary by Aikido

⚠️ Security Issues: 1 🔍 Quality Issues: 4 Resolved Issues: 0

🚀 New Features

  • Introduced pure-Python ip_matcher_fallback implementation and modules

⚡ Enhancements

  • Enabled optional pytricia usage with preparse and warning message

🔧 Refactors

  • Refactored callers to pass network lists to IPMatcher constructor

More info

@bitterpanda63 bitterpanda63 changed the title IPMatcher: Switch node logic out in favour of pytricia Use pytricia for ip matching on non-windows machines Jan 14, 2026

def test_with_ranges():
input_list = [
"192.168.0.0/24",
Copy link
Member

Choose a reason for hiding this comment

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

Maybe good to test with multiple overlapping ranges too?

Copy link
Member Author

@bitterpanda63 bitterpanda63 Jan 15, 2026

Choose a reason for hiding this comment

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

these test cases are from node iirc? (also a bit out of scope, since this was existing code copied over)

matcher = IPMatcher(input_list)
assert matcher.has("::ffff:0.0.0.0") == True
assert matcher.has("::ffff:127.0.0.1") == True
assert matcher.has("::ffff:123") == False
Copy link
Member

Choose a reason for hiding this comment

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

so this case is different for both?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, PyTricia is more accurate in this regard, this is also not a huge issue, and I think no one is running with windows in production. Given IPC also doesnt work

# Block the IP address used by Alibaba Cloud
imds_addresses.add("100.100.100.200")
imds_addresses.add(map_ipv4_to_ipv6("100.100.100.200"))
imds_addresses = IPMatcher(

Choose a reason for hiding this comment

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

imds_addresses is a module-level IPMatcher initialized at import; it will persist across requests and may unintentionally cache data between requests. Consider making it request-scoped or explicitly documenting intended shared cache.

Details

✨ AI Reasoning
​A module-level variable is being initialized during import and stored for the process lifetime. This can unintentionally cache request- or environment-specific data between requests/workers, causing cross-request leakage or stale data. The change replaces the prior empty-initialization line with a populated IPMatcher created at module import, increasing the chance that runtime state is shared across requests.

🔧 How do I fix it?
Avoid storing request-specific data in module-level variables. Use request-scoped variables or explicitly mark shared caches as intentional.

Reply @AikidoSec feedback: [FEEDBACK] to get better review comments in the future.
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info

@bitterpanda63 bitterpanda63 merged commit d2b2c95 into main Feb 6, 2026
84 checks passed
@bitterpanda63 bitterpanda63 deleted the test-with-pytricia branch February 6, 2026 12:36
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.

3 participants