-
Notifications
You must be signed in to change notification settings - Fork 510
fix(commands): Improve phone number input validation of OCC commands #17173
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
Draft
nickvergessen
wants to merge
3
commits into
main
Choose a base branch
from
bugfix/noid/improve-phonenumber-validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+100
−10
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
0bccb9a
fix(commands): Improve phone number input validation of OCC commands
nickvergessen 6166c86
fixup! fix(commands): Improve phone number input validation of OCC co…
nickvergessen ba6e346
fix(sip): Check for invalid phone numbers in setupcheck
nickvergessen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Talk\Service; | ||
|
|
||
| use OCP\IConfig; | ||
| use OCP\IPhoneNumberUtil; | ||
|
|
||
| class PhoneNumberValidation { | ||
|
|
||
| public function __construct( | ||
| protected IPhoneNumberUtil $phoneNumberUtil, | ||
| protected IConfig $config, | ||
| ) { | ||
| } | ||
|
|
||
| /** | ||
| * Validate input as a phone number | ||
| * | ||
| * - Local number: allow | ||
| * - International number: | ||
| * 1. Replace leading 00 with + | ||
| * 2. Check if still valid international number | ||
| * a. If valid, strip + and allow | ||
| * b. If invalid, throw | ||
| * @throws \InvalidArgumentException When the number is invalid | ||
| */ | ||
| public function validateNumber(string $phoneNumber): string { | ||
|
|
||
| if ( | ||
| // Not an internation number | ||
| !str_starts_with($phoneNumber, '00') | ||
| // And matches a local number or dial-through | ||
| && preg_match('/^[0-9]{1,20}$/', $phoneNumber) | ||
| ) { | ||
| return $phoneNumber; | ||
| } | ||
|
|
||
| // Replace double leading zero with + | ||
| if (str_starts_with($phoneNumber, '00')) { | ||
| $phoneNumber = '+' . substr($phoneNumber, 2); | ||
| } | ||
|
|
||
| $defaultRegion = $this->config->getSystemValueString('default_phone_region') ?: null; | ||
| $standardPhoneNumber = $this->phoneNumberUtil->convertToStandardFormat($phoneNumber, $defaultRegion); | ||
|
|
||
| if ($standardPhoneNumber === null) { | ||
| throw new \InvalidArgumentException(); | ||
| } | ||
|
|
||
| if (str_starts_with($standardPhoneNumber, '+')) { | ||
| return substr($standardPhoneNumber, 1); | ||
| } | ||
|
|
||
| return $standardPhoneNumber; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fancycode is the free pass for local numbers okay? Or should e.g.
0711be replaced with49711if DE is specified as default phone prefix. I assume it would be bad, as it would prevent specifying 0711… even if that would be what your SIP gate receivesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An internal extension should never start with a
0, so you could add the international prefix if configured (i.e.071112345becomes+4971112345) or just reject such numbers.To make things worse, the
00prefix for international numbers is only if calling from Germany to another country. For example calling from the US to another country needs011as prefix, from Australia it's0011. See https://en.wikipedia.org/wiki/List_of_international_call_prefixes for other prefixes. So replacing00with a+will fail for Australian people trying to configure00114971112345as German number in Stuttgart.You could try to guess based on the default phone prefix what the user might try to do, but maybe the easiest is to simply reject numbers that start with a
0.