-
Notifications
You must be signed in to change notification settings - Fork 3
fix: subnet route CIDRs may not have host bits set #89
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
Conversation
Closes #88 Signed-off-by: Derek Kaser <[email protected]>
WalkthroughFrontend and backend CIDR validation were hardened: client adds ipaddr.js and new CIDRResult enum with precise host-bits checking; server replaces manual CIDR parsing with php-ip's IPBlock to ensure subnet route CIDRs are network addresses. A UI element was added for validation feedback. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks and finishing touches✅ Passed checks (4 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🔇 Additional comments (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/usr/local/emhttp/plugins/tailscale/include/Pages/Tailscale.php (1)
174-194: Consider internationalizing the validation error messages.The hardcoded English strings (
'Invalid CIDR: Host bits may not be set'and'Invalid CIDR') are inconsistent with the translation pattern used elsewhere in this codebase (e.g.,$tr->tr("needs_login")). Consider injecting translated strings from PHP for consistency.🔎 Suggested approach
Pass translated messages from PHP and use them in the JavaScript:
+const validationMessages = { + hostbits: '<?= $tr->tr("validation.hostbits_set") ?>', + invalid: '<?= $tr->tr("validation.invalid_cidr") ?>' +}; + function validateTailscaleRoute() { switch(isValidCIDR($('#tailscaleRoute').val())) { case CIDRResult.VALID: $('#tailscaleRouteValidation').text(''); $('#addTailscaleRoute').prop('disabled', false); break; case CIDRResult.HOSTBITS_SET: - $('#tailscaleRouteValidation').text('Invalid CIDR: Host bits may not be set').css('color', 'red'); + $('#tailscaleRouteValidation').text(validationMessages.hostbits).css('color', 'red'); $('#addTailscaleRoute').prop('disabled', true); break; case CIDRResult.EMPTY: $('#tailscaleRouteValidation').text(''); $('#addTailscaleRoute').prop('disabled', true); break; case CIDRResult.INVALID: default: - $('#tailscaleRouteValidation').text('Invalid CIDR').css('color', 'red'); + $('#tailscaleRouteValidation').text(validationMessages.invalid).css('color', 'red'); $('#addTailscaleRoute').prop('disabled', true); break; } }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
src/usr/local/emhttp/plugins/tailscale/lib/ipaddr.min.jsis excluded by!**/*.min.jssrc/usr/local/php/unraid-tailscale-utils/composer.lockis excluded by!**/*.lock
📒 Files selected for processing (4)
src/usr/local/emhttp/plugins/tailscale/include/Pages/Tailscale.php(2 hunks)src/usr/local/emhttp/plugins/tailscale/include/data/Config.php(1 hunks)src/usr/local/php/unraid-tailscale-utils/composer.json(1 hunks)src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/Utils.php(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-11T00:22:27.117Z
Learnt from: dkaser
Repo: unraid/unraid-tailscale PR: 66
File: src/usr/local/emhttp/plugins/tailscale/include/Pages/Settings.php:218-218
Timestamp: 2025-11-11T00:22:27.117Z
Learning: In the unraid-tailscale plugin, pages with `Tabs="true"` (like Tailscale.page) and their submenu pages (like Tailscale-1-Settings.page) share the same JavaScript scope. JavaScript functions defined in Tailscale.php are accessible in Settings.php because they load in the same browser context.
Applied to files:
src/usr/local/emhttp/plugins/tailscale/include/Pages/Tailscale.php
🧬 Code graph analysis (1)
src/usr/local/emhttp/plugins/tailscale/include/data/Config.php (1)
src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/Info.php (1)
tr(66-69)
🔇 Additional comments (4)
src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/Utils.php (1)
89-99: Clean implementation using the library for CIDR validation.The logic correctly validates that the input CIDR represents a network address by comparing it against the computed network address from
IPBlock. This ensures host bits are zero.src/usr/local/emhttp/plugins/tailscale/include/data/Config.php (1)
175-175: LGTM! Clean UI addition for validation feedback.The
<span id="tailscaleRouteValidation">element provides a proper target for displaying client-side validation messages, and theoninputhandler ensures real-time feedback as the user types.src/usr/local/emhttp/plugins/tailscale/include/Pages/Tailscale.php (2)
139-172: Solid validation implementation with proper host bits detection.The
CIDRResultenum pattern and the validation logic correctly identify when host bits are set by comparing the input address against the computed network address. The try-catch properly handles malformed input.
48-49: LGTM! Good choice of library for client-side IP address validation.The
ipaddr.jslibrary is a well-established JavaScript library for manipulating IP addresses in JavaScript environments that allows you to verify and parse IP addresses and match them against CIDR ranges. Theipaddr.min.jsfile is present in the plugin distribution at the expected location.
Signed-off-by: Derek Kaser <[email protected]>
Closes #88
Summary by CodeRabbit
New Features
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.