Skip to content

Detect ip6 with admin login #1084

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

Merged
merged 2 commits into from
Jun 12, 2025
Merged

Conversation

michield
Copy link
Member

@michield michield commented Jun 8, 2025

Description

on the admin remote IP login check, detect that it is an IPv6 address and use it like that.

Related Issue

Screenshots (if appropriate):

@michield michield requested review from TatevikGr and bramley June 8, 2025 17:20
@michield michield changed the base branch from main to release-3.7.0 June 8, 2025 17:21
@michield michield added the 3.7.x PRs for 3.7 label Jun 9, 2025
@@ -301,6 +301,7 @@ function mb_strtolower($string)
if (!empty($GLOBALS['require_login'])) {
//bth 7.1.2015 to support x-forwarded-for
$remoteAddr = getClientIP();
$isIP4 = preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $remoteAddr);

Choose a reason for hiding this comment

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

The regex is returning false positives. This doesn't impact the result in this case (since the IP is coming from the request} filter_var($remoteAddr, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false is a more reliable option

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, I was looking at that as well, but went the simple option. I think the regex will do, as it's a simple match, and as you say, we're not validating the IP address, just checking that it's IPv4 vs IPv6. Not sure how fast the filter_var option is in comparison.

@bramley
Copy link
Contributor

bramley commented Jun 9, 2025

I cannot see anywhere that needs to distinguish between v4 and v6 addresses. Is it valid for a session to change from a v4 address to a v6 address? But I don't think that is handled anyway.

I think it would be clearer to use just one field on the admin_login table rather than two. The remote_ip6 is already large enough so use that field regardless and rename it.

There is also a use of the admin_login table in upgrade.php that needs changing.

@michield
Copy link
Member Author

michield commented Jun 9, 2025

I'd rather not unnecessarily change database tables. I made the choice at the time to have two columns and who knows, this may come in useful at some point.

@michield michield merged commit b473478 into release-3.7.0 Jun 12, 2025
8 checks passed
@michield michield mentioned this pull request Jun 23, 2025
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants