Skip to content

fix(commands): Improve phone number input validation of OCC commands - #17173

Merged
nickvergessen merged 3 commits into
mainfrom
bugfix/noid/improve-phonenumber-validation
Mar 30, 2026
Merged

fix(commands): Improve phone number input validation of OCC commands#17173
nickvergessen merged 3 commits into
mainfrom
bugfix/noid/improve-phonenumber-validation

Conversation

@nickvergessen

@nickvergessen nickvergessen commented Feb 19, 2026

Copy link
Copy Markdown
Member

β˜‘οΈ Resolves

πŸ› οΈ API Checklist

🚧 Tasks

  • Add a setupcheck:
    grafik

🏁 Checklist

  • ⛑️ Tests (unit and/or integration) are included or not possible
  • πŸ“˜ API documentation in docs/ has been updated or is not required
  • πŸ”– Capability is added or not needed

@nickvergessen nickvergessen self-assigned this Feb 19, 2026
@nickvergessen nickvergessen added feature: api πŸ› οΈ OCS API for conversations, chats and participants feature: SFU & SIP ☎️ labels Feb 19, 2026
@nickvergessen
nickvergessen marked this pull request as draft February 19, 2026 23:00
// And matches a local number or dial-through
&& preg_match('/^[0-9]{1,20}$/', $phoneNumber)
) {
return $phoneNumber;

Copy link
Copy Markdown
Member Author

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. 0711 be replaced with 49711 if 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 receives

Copy link
Copy Markdown
Member

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. 071112345 becomes +4971112345) or just reject such numbers.

To make things worse, the 00 prefix for international numbers is only if calling from Germany to another country. For example calling from the US to another country needs 011 as prefix, from Australia it's 0011. See https://en.wikipedia.org/wiki/List_of_international_call_prefixes for other prefixes. So replacing 00 with a + will fail for Australian people trying to configure 00114971112345 as 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

So the only thing I can do is look for a leading 0 or +
try to convert to standard and strip of the +, if there was no + return it's invalid?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, I think that would be the best, though libphonenumber supports detecting valid numbers with a leading 0 if a country is configured.

Some testcases (assuming DE is configured as default phone country):

4971112345 -> 4971112345
+4971112345 -> 4971112345
4911223344 -> reject (should be detected to be invalid by libphonenumber)
+4911223344 -> reject (should be detected to be invalid by libphonenumber)
004971112345 -> 4971112345 (should be detected to be valid by libphonenumber, would be invalid if Australia is configured as default phone country)
00112345678901 -> 112345678901 (looks like a valid US number for libphonenumber)
00111122233344 -> reject (not a valid US number)
071112345 -> 4971112345 (0711 is a German local prefix)
011223344 -> reject (01122 is not a valid German local prefix)
3001 -> 3001 (might be an extension in a local PBX)
03001 -> reject (030 could be Berlin but 01 is too short) 

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

00112345678901 -> 112345678901 (looks like a valid US number for libphonenumber)

This one is striping off a leading 1, but sure why. But the normalizing returns: +12345678901 so only a single 1 not 2 as you posted.

@nickvergessen
nickvergessen force-pushed the bugfix/noid/improve-phonenumber-validation branch from ba6e346 to 9111c65 Compare March 6, 2026 09:23
@nickvergessen
nickvergessen requested a review from fancycode March 6, 2026 09:25
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
@nickvergessen
nickvergessen force-pushed the bugfix/noid/improve-phonenumber-validation branch from 9111c65 to 062bacc Compare March 20, 2026 13:09
@nickvergessen
nickvergessen marked this pull request as ready for review March 20, 2026 13:11
@nickvergessen
nickvergessen merged commit 107d8c2 into main Mar 30, 2026
82 checks passed
@nickvergessen
nickvergessen deleted the bugfix/noid/improve-phonenumber-validation branch March 30, 2026 15:38
@nickvergessen

Copy link
Copy Markdown
Member Author

/backport to stable33

@nickvergessen

Copy link
Copy Markdown
Member Author

/backport to stable32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: api πŸ› οΈ OCS API for conversations, chats and participants feature: SFU & SIP ☎️

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants