Skip to content

PageCache/AccessList: Add CIDR support #37809

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

Open
wants to merge 3 commits into
base: 2.4-develop
Choose a base branch
from

Conversation

tdgroot
Copy link
Member

@tdgroot tdgroot commented Jul 27, 2023

Description (*)

When accepting purge requests within a network, it's easier to just supply a CIDR range.

Related Pull Requests

None.

Fixed Issues (if relevant)

None.

Manual testing scenarios (*)

  1. Go to Advanced -> System -> Full Page Cache -> Varnish Configuration
  2. Configure a CIDR range like 172.16.0.1/24
  3. Value should be valid and saved

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

Resolved issues:

  1. resolves [Issue] PageCache/AccessList: Add CIDR support #39953: PageCache/AccessList: Add CIDR support

@m2-assistant
Copy link

m2-assistant bot commented Jul 27, 2023

Hi @tdgroot. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.

Add the comment under your pull request to deploy test or vanilla Magento instance:
  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@tdgroot tdgroot force-pushed the page_cache_acl_cidr branch from 24526c2 to 1c7183c Compare July 27, 2023 15:10
@engcom-Hotel engcom-Hotel added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Aug 1, 2023
@engcom-Hotel
Copy link
Contributor

@magento run all tests

@engcom-Hotel
Copy link
Contributor

@magento create issue

@github-project-automation github-project-automation bot moved this to Pending Review in Pull Requests Dashboard May 30, 2025
@engcom-Hotel engcom-Hotel moved this from Pending Review to On Hold in Pull Requests Dashboard May 30, 2025
@engcom-Hotel engcom-Hotel added Triage: Need PO Confirmation Requirements should be clarified/approved/confirmed with Product Manager. Not ready for fix/delivery and removed Progress: on hold labels May 30, 2025
@engcom-Hotel
Copy link
Contributor

Hello @tdgroot,

Thanks for the contribution!

But as this is feature enhancement, we need a PO confirmation to proceed with this PR. We have started the process for the same. Meanwhile we are moving this PR On Hold.

Thanks

@engcom-Hotel
Copy link
Contributor

@magento run all tests

@engcom-Hotel
Copy link
Contributor

Hello @tdgroot,

We have received an approval for this PR for further evaluation. Hence moving it to appropriate bucket.

Thanks

@engcom-Hotel engcom-Hotel moved this from On Hold to Review in Progress in Pull Requests Dashboard Jun 3, 2025
Copy link
Contributor

@engcom-Hotel engcom-Hotel left a comment

Choose a reason for hiding this comment

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

Hello @tdgroot,

Thank you for your contribution to add CIDR notation support to PageCache access lists. This is a valuable enhancement that would allow for more flexible IP-based access control.

However, the PR currently only modifies the validation pattern without implementing the actual CIDR functionality. For full CIDR support, we need changes in:

  • The component that performs IP matching against the access list
  • A utility method to properly compare an IP against a CIDR range

Thanks

@@ -24,7 +24,7 @@ public function beforeSave()
parent::beforeSave();

$value = $this->getValue();
if (!is_string($value) || !preg_match('/^[\w\s\.\-\,\:]+$/', $value)) {
if (!is_string($value) || !preg_match('/^[\w\s\.\-\,\:(\/\d+)?]+$/', $value)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. The pattern places (\/\d+)? inside a character class ([...]), which means these are treated as individual characters rather than a sequence.
  2. The pattern remains overly permissive and would validate strings like "this is: a more / or less, valid string.... oh, lets add numbers 12345" which aren't valid IP addresses or CIDR notations

Copy link
Contributor

Choose a reason for hiding this comment

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

The extra CIDR validation regex should indeed be moved outside of the character class, so should become something like this: ^[\w\s\.\-\,\:]+(\/\d+)?$
Good remark!

@engcom-Hotel engcom-Hotel removed the Triage: Need PO Confirmation Requirements should be clarified/approved/confirmed with Product Manager. Not ready for fix/delivery label Jun 3, 2025
@engcom-Hotel engcom-Hotel moved this from Review in Progress to Changes Requested in Pull Requests Dashboard Jun 3, 2025
@hostep
Copy link
Contributor

hostep commented Jun 7, 2025

However, the PR currently only modifies the validation pattern without implementing the actual CIDR functionality. For full CIDR support, we need changes in:

The component that performs IP matching against the access list
A utility method to properly compare an IP against a CIDR range

That's not really true, the only place where we use this configuration value is over here:


Which is used to output the access list into the VCL file that Magento generates for Varnish.
Varnish already supports CIDR notation in ACL's, so there is no need for extra matching or parsing.

One thing that I'm not sure about, but maybe @tdgroot can clarify, is that the Varnish docs say to put the IP address in double quotes and the CIDR part outside of those quotes: https://varnish-cache.org/docs/trunk/users-guide/vcl-example-acls.html#acls
In this Magento code, the CIDR part would be included inside the double quotes. I have no idea if this will cause issues or will just work as expected?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: needs update Project: Community Picked PRs upvoted by the community
Projects
Status: Changes Requested
Development

Successfully merging this pull request may close these issues.

[Issue] PageCache/AccessList: Add CIDR support
4 participants