Skip to content
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

2FA: Add pattern to validate phone number format as per E.164 #5538

Open
wants to merge 6 commits into
base: 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
3 changes: 2 additions & 1 deletion lib/sms.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
/**
* Send an SMS message to the specified numbers using the Twilio API
*
* @param int|array Nnumber(s) to send an SMS to. Accepts formatted and unformatted US numbers, e.g. +14155551212, (415) 555-1212 or 415-555-1212.
* @param int|array Number(s) to send an SMS to. Accepts phone numbers in E.164 format e.g. +14155551212
* @param string Message to send. Longer than 140 chars will be split.
*
* @link http://www.twilio.com/docs/api/rest/sending-sms
* @link https://www.twilio.com/docs/glossary/what-e164
*/
function send_sms( $to, $message ) {

Expand Down
7 changes: 5 additions & 2 deletions wpcom-vip-two-factor/sms-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,15 @@ public function user_options( $user ) {
<?php else : ?>
<label>Phone Number
<input name="vip-two-factor-phone" type="tel"
pattern="^\+[1-9]\d{1,14}$"
Copy link
Member

Choose a reason for hiding this comment

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

ITU-T specifies that a phone number cannot be longer than fifteen digits, with one to three digits reserved for the country calling code, but valid numbers in Germany have been assigned that are longer than this.

-- https://github.com/google/libphonenumber/blob/master/FALSEHOODS.md

value="<?php echo esc_attr( $sms ); ?>"/>
</label>
<!-- Requires E.164 format for telephone numbers https://www.twilio.com/docs/glossary/what-e164 -->
<input type="submit" class="button" name="vip-two-factor-phone-send-code"
value="<?php esc_attr_e( 'Submit', 'two-factor' ); ?>"/>
<p><strong>Note:</strong> Please include your country calling code (e.g. +44, +1, +61, etc.) to ensure
SMS messages are correctly sent.</p>
<p><strong>Note:</strong> Please include your country calling code (e.g. +44, +1, +61, etc.) so that the
phone number is as per <a href="https://www.twilio.com/docs/glossary/what-e164" target="_blank" rel="noopener">E.164 standards</a>,
thereby ensuring that the SMS messages are sent correctly.</p>
<?php endif; ?>
</div>
<?php
Expand Down
Loading