Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpFoundation][FrameworkBundle] Add CIDR notation support in trusted proxy list #7312

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
wants to merge 2 commits into from

Conversation

lazyhammer
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR symfony/symfony-docs#2287

Added CIDR notation support as requested in #7262.

Also, as long as we need to check against a list of IPs at least in 3 places:

does it make sense to modify IpUtils' methods to also accept array as second argument?

}
}

break;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is breaking intended here ?

Maybe Continue should be return ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If checkIp() was able to match against array, I could simplify it to this:

do {
    $clientIp = array_pop($clientIps);

    if (!IpUtils::checkIp($clientIp, $trustedProxy)) {
        return $clientIp;
    }
} while ($clientIps);

But for now, since we need to check other trusted proxies in the loop, we can't return when false === checkIp(), and we can't return when true === checkIp() as well, since there may be another trusted proxy up the list. That's why I use continue within inner loop, and then break outer loop in case $clientIp does not match any of trusted ips.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or maybe that looks better?

    $clientIp = $ip;

    while (list( , $trustedProxy) = each($trustedProxies)) {
        if (IpUtils::checkIp($clientIp, $trustedProxy)) {
            if (!$clientIps) {
                return $clientIp;
            }

            $clientIp = array_pop($clientIps);
            reset($trustedProxies);
        }
    }

Copy link
Member

Choose a reason for hiding this comment

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

Why not:

foreach (array_reverse($clientIps) as $clientIp) {
    foreach ($trustedProxies as $trustedProxy) {
        if (IpUtils::checkIp($clientIp, $trustedProxy)) {
            continue;
        }
    }

    return $clientIp;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's much more readable! 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

@acasademont
Copy link
Contributor

+1 we are stuck on the deprecated trust_proxy_headers because the Amazon ELB changes its IP's

@bassrock
Copy link

👍 for the amazon issue here too

@fabpot
Copy link
Member

fabpot commented Apr 20, 2013

Closing in favor of #7735

@fabpot fabpot closed this Apr 20, 2013
fabpot added a commit that referenced this pull request Apr 20, 2013
This PR was merged into the master branch.

Discussion
----------

[HttpFoundation][FrameworkBundle] Add CIDR notation support in trusted proxy list

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #7312, #7262
| License       | MIT
| Doc PR        | symfony/symfony-docs#2287

Should be rebased once #7734 is merged.

Commits
-------

7b32794 [HttpFoundation] updated CHANGELOG
e7c1696 [HttpFoundation] refactored code to avoid code duplication
1695067 [HttpFoundation] added some unit tests for ranges of trusted IP addresses
811434f Allow setting trusted_proxies using CIDR notation
ddc9e38 Modify Request::getClientIp() to use IpUtils::checkIp()
@lazyhammer lazyhammer deleted the trusted-proxies-cidr branch April 21, 2013 11:18
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.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.