Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[HttpClient] adding NoPrivateNetworkHttpClient decorator#35566

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

hallboav
Copy link
Contributor

@hallboavhallboav commentedFeb 3, 2020
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
Deprecations?no
Tickets-
LicenseMIT
Doc PR-

The purpose of NoPrivateNetworkHttpClient is for block requests to private networks by default or block one or more subnetwork if specified. NoPrivateNetworkHttpClient accepts two arguments, first one is a HttpClientInterface instance and subnetworks as a second argument.
Second argument $subnets can be null for blocking requests to private networks, or string to specify a single subnet of array for a set of subnets.

<?phpuseSymfony\Component\HttpClient\HttpClient;useSymfony\Component\HttpClient\NoPrivateNetworkHttpClient;$client =newNoPrivateNetworkHttpClient(HttpClient::create());// You can request public networks normally using the code above$client->request('GET','https://symfony.com/');// Requests to private neworks will be blocked because second argument ($subnets) is null$client->request('GET','http://localhost/');// If we request from 104.26.14.0 to 104.26.15.255 we'll get an exception, since I'm specifying a subnetwork$client =newNoPrivateNetworkHttpClient(HttpClient::create(), ['104.26.14.0/23']);// Let's suppose that our DNS server resolves symfony.com to 104.26.14.6, then the following request will be blocked$client->request('GET','https://symfony.com/');

{
use HttpClientTrait;

const PRIVATE_SUBNETS = [
Copy link
Contributor

Choose a reason for hiding this comment

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

public or private?

Choose a reason for hiding this comment

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

public LGTM

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Why public?

Choose a reason for hiding this comment

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

so that ppl can reuse it?
private works for me also!

Copy link
ContributorAuthor

@hallboavhallboavFeb 3, 2020
edited
Loading

Choose a reason for hiding this comment

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

Ahhh, I thought you were talking about the name of the constant. Thank you!

Choose a reason for hiding this comment

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

private const PRIVATE_SUBNETS works

@nicolas-grekasnicolas-grekas added this to thenext milestoneFeb 3, 2020
Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!
Just minor comments remaining.

{
use HttpClientTrait;

const PRIVATE_SUBNETS = [

Choose a reason for hiding this comment

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

public LGTM

@hallboavhallboavforce-pushed theno-private-network-http-client-decorator branch fromc5147dd toe48b6d5CompareFebruary 3, 2020 13:33
@hallboav
Copy link
ContributorAuthor

@nicolas-grekas@OskarStark
I made all the changes you requested.

OskarStark reacted with heart emoji

@nicolas-grekasnicolas-grekasforce-pushed theno-private-network-http-client-decorator branch frome48b6d5 to63fec80CompareFebruary 3, 2020 16:39
@nicolas-grekas
Copy link
Member

Thank you@hallboav.

hallboav reacted with laugh emojihallboav reacted with hooray emoji

nicolas-grekas added a commit that referenced this pull requestFeb 3, 2020
…or (hallboav)This PR was merged into the 5.1-dev branch.Discussion----------[HttpClient] adding NoPrivateNetworkHttpClient decorator| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| Deprecations? | no| Tickets       | -| License       | MIT| Doc PR        | -The purpose of NoPrivateNetworkHttpClient is for block requests to private networks by default or block one or more subnetwork if specified. NoPrivateNetworkHttpClient accepts two arguments, first one is a HttpClientInterface instance and subnetworks as a second argument.Second argument $subnets can be null for blocking requests to private networks, or string to specify a single subnet of array for a set of subnets.```php<?phpuse Symfony\Component\HttpClient\HttpClient;use Symfony\Component\HttpClient\NoPrivateNetworkHttpClient;$client = new NoPrivateNetworkHttpClient(HttpClient::create());// You can request public networks normally using the code above$client->request('GET', 'https://symfony.com/');// Requests to private neworks will be blocked because second argument ($subnets) is null$client->request('GET', 'http://localhost/');// If we request from 104.26.14.0 to 104.26.15.255 we'll get an exception, since I'm specifying a subnetwork$client = new NoPrivateNetworkHttpClient(HttpClient::create(), ['104.26.14.0/23']);// Let's suppose that our DNS server resolves symfony.com to 104.26.14.6, then the following request will be blocked$client->request('GET', 'https://symfony.com/');```Commits-------63fec80 [HttpClient] adding NoPrivateNetworkHttpClient decorator
@nicolas-grekasnicolas-grekas merged commit63fec80 intosymfony:masterFeb 3, 2020
@nicolas-grekasnicolas-grekas modified the milestones:next,5.1May 4, 2020
@fabpotfabpot mentioned this pull requestMay 5, 2020
nicolas-grekas added a commit that referenced this pull requestMar 20, 2023
…r1337)This PR was squashed before being merged into the 6.3 branch.Discussion----------[HttpFoundation] Add IpUtils::isPrivateIp| Q             | A| ------------- | ---| Branch?       | 6.3| Bug fix?      | no| New feature?  | yes| Deprecations? | no| Tickets       | N/A| License       | MIT| Doc PR        |symfony/symfony-docs#18102This is only my second PR for this project, so I hope I followed all the guidelines correctly.Recently I had more and more use cases where I had to make exceptions (mostly rate limiting) for private IP ranges.Symfony currently does not provide an easy way to check if an IP is private or public but implements such logic internally (private constant) for the [NoPrivateNetworkHttpClient](https://github.com/symfony/symfony/blob/6.3/src/Symfony/Component/HttpClient/NoPrivateNetworkHttpClient.php).This PR intents to make the private subnet list reusable by adding it to [IpUtils](https://github.com/symfony/symfony/blob/6.3/src/Symfony/Component/HttpFoundation/IpUtils.php).In the original PR of the NoPrivateNetworkHttpClient it was also briefly mentioned that this constant may have value when made public.#35566 (comment)I think symfony should and always should have exposed this constant.Commits-------6471582 [HttpFoundation] Add IpUtils::isPrivateIp
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@OskarStarkOskarStarkOskarStark left review comments

@fabpotfabpotfabpot approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
5.1
Development

Successfully merging this pull request may close these issues.

5 participants
@hallboav@nicolas-grekas@fabpot@OskarStark@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp