Skip to content

align allowed characters for option --value on console command config:delete to config:set #20764

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 20, 2023

Conversation

ziegenberg
Copy link
Contributor

Description:

The console command config:set allows any character for the --value option (see: \Piwik\Plugins\CoreAdminHome\Commands\SetConfig\ConfigSettingManipulation::make).

The regex used for config:set is: /^([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)(\[\])?=(.*)/

The console command config:delete only allows characters a to z (upper and lower case), numbers and the underscore. This prevents one from deleting configs values like IPv4 or IPV6 addresses, mail addresses, networks or IP ranges and lists of values. The currently used regex is: /^([a-zA-Z0-9_]+)(?:\.([a-zA-Z0-9_]+))?(?:\[\])?(?:\.([a-zA-Z0-9_]+))?/

The following is a list of possible settings found in the wild. Those can be set with console config:set but cannot be deleted.

[General]
login_allowlist_ip[] = "123.123.123.123"
trusted_hosts = "[2001:858:6::186]:80"
contact_email_address = "no-reply+with-extension@test.at"
proxy_ips[] = "192.168.x.x/24"

[HeatmapSessionRecording]
session_recording_sample_limits = 50,100,250,500,1000,2000,5000

This commit aligns the allowed characters for the option --value on the console command config:delete to the ones for config:set and changes the regex to
/^([a-zA-Z0-9_]+)(?:\.([a-zA-Z0-9_]+))?(?:\[\])?(?:\.(.+))?/.

Fixes: #19966

If we do not want to accept all special characters we could also go with the following regex:
/^([a-zA-Z0-9_]+)(?:\.([a-zA-Z0-9_]+))?(?:\[\])?(?:\.([a-zA-Z0-9\x28-\x2F\[\]_:@]+))?

Besides the well-known character classes (a-zA-Z0-9) this allows the following characters:

  • \x28-\x2F: (, ), *, +, ,, -, ., /
  • [, ], _, :, @

Review

@github-actions
Copy link
Contributor

github-actions bot commented Jun 6, 2023

If you don't want this PR to be closed automatically in 28 days then you need to assign the label 'Do not close'.

@github-actions github-actions bot added the Stale The label used by the Close Stale Issues action label Jun 6, 2023
@sgiehl sgiehl added Needs Review PRs that need a code review and removed Stale The label used by the Close Stale Issues action labels Jun 6, 2023
@github-actions
Copy link
Contributor

This issue is in "needs review" but there has been no activity for 7 days. ping @matomo-org/core-reviewers

@github-actions github-actions bot added the Stale The label used by the Close Stale Issues action label Jun 14, 2023
@ziegenberg
Copy link
Contributor Author

@matomo-org/core-reviewers Can I get a review on this?

@github-actions github-actions bot removed the Stale The label used by the Close Stale Issues action label Jun 15, 2023
…ig:delete to config:set

The console command `config:set` allows any character for the `--value`
option (see:
`\Piwik\Plugins\CoreAdminHome\Commands\SetConfig\ConfigSettingManipulation::make`).

The regex used for `config:set` is:
`/^([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)(\[\])?=(.*)/`

The console command `config:delete` only allows characters a to z (upper
and lower case), numbers and the underscore. This prevents one from
deleting configs values like IPv4 or IPV6 addresses, mail addresses,
networks or IP ranges and lists of values. The currently used regex is:
`/^([a-zA-Z0-9_]+)(?:\.([a-zA-Z0-9_]+))?(?:\[\])?(?:\.([a-zA-Z0-9_]+))?/`

The following is a list of possible settings found in the wild. Those
can be set with `console config:set` but cannot be deleted.

```
[General]
login_allowlist_ip[] = "123.123.123.123"
trusted_hosts = "[2001:858:6::186]:80"
contact_email_address = "no-reply+with-extension@test.at"
proxy_ips[] = "192.168.x.x/24"

[HeatmapSessionRecording]
session_recording_sample_limits = 50,100,250,500,1000,2000,5000
```

This commit aligns the allowed characters for the option `--value` on
the console command `config:delete` to the ones for `config:set` and
changes the regex to
`/^([a-zA-Z0-9_]+)(?:\.([a-zA-Z0-9_]+))?(?:\[\])?(?:\.(.+))?/`.

Fixes: matomo-org#19966

Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>
Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>
@sgiehl sgiehl force-pushed the fix-console-command-delete branch from f8e65e0 to 3cda269 Compare June 20, 2023 09:23
Copy link
Member

@sgiehl sgiehl left a comment

Choose a reason for hiding this comment

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

Did some local testing and seems to fix the described problem. Well done @ziegenberg 🎉

@sgiehl sgiehl merged commit e825b18 into matomo-org:5.x-dev Jun 20, 2023
@sgiehl sgiehl added this to the 5.0.0 milestone Jun 20, 2023
@sgiehl sgiehl added the not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. label Aug 1, 2023
@ziegenberg ziegenberg deleted the fix-console-command-delete branch January 10, 2024 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Development

Successfully merging this pull request may close these issues.

Unable to delete entry containing dots with config:delete command
2 participants