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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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!

throw new LocalizedException(
new Phrase(
'Access List value "%1" is not valid. '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public static function getValidValues(): array
[null, 'localhost'],
['127.0.0.1', '127.0.0.1'],
['127.0.0.1, localhost, ::2', '127.0.0.1, localhost, ::2'],
['172.16.0.1/24, 2001:0db8:/32', '172.16.0.1/24, 2001:0db8:/32'],
];
}

Expand Down