-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tighten Vapid subject validation (#789)
only accept Vapid subjects with https: or mailto: URL protocols, as per spec add tests for localhost https: and mailto: subjects
- Loading branch information
Showing
2 changed files
with
38 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -9,8 +9,12 @@ const webPush = require('../src/index'); | |
const vapidHelper = require('../src/vapid-helper'); | ||
|
||
const VALID_AUDIENCE = 'https://example.com'; | ||
const VALID_SUBJECT_MAILTO = 'mailto: [email protected]'; | ||
const VALID_SUBJECT_URL = 'https://exampe.com/contact'; | ||
const VALID_SUBJECT_MAILTO = 'mailto:[email protected]'; | ||
const VALID_SUBJECT_LOCALHOST_MAILTO = 'mailto:user@localhost'; | ||
const VALID_SUBJECT_URL = 'https://example.com/contact'; | ||
const WARN_SUBJECT_LOCALHOST_URL = 'https://localhost'; | ||
const INVALID_SUBJECT_URL_1 = 'http://example.gov'; | ||
const INVALID_SUBJECT_URL_2 = 'ftp://example.net'; | ||
const VALID_PUBLIC_KEY = urlBase64.encode(Buffer.alloc(65)); | ||
const VALID_UNSAFE_BASE64_PUBLIC_KEY = Buffer.alloc(65).toString('base64'); | ||
const VALID_PRIVATE_KEY = urlBase64.encode(Buffer.alloc(32)); | ||
|
@@ -101,6 +105,14 @@ suite('Test Vapid Helpers', function() { | |
function() { | ||
vapidHelper.getVapidHeaders('Not a URL', VALID_SUBJECT_MAILTO, VALID_PUBLIC_KEY, VALID_PRIVATE_KEY); | ||
}, | ||
function() { | ||
// http URL protocol | ||
vapidHelper.getVapidHeaders(VALID_AUDIENCE, INVALID_SUBJECT_URL_1, VALID_PUBLIC_KEY, VALID_PRIVATE_KEY); | ||
}, | ||
function() { | ||
// ftp URL protocol | ||
vapidHelper.getVapidHeaders(VALID_AUDIENCE, INVALID_SUBJECT_URL_2, VALID_PUBLIC_KEY, VALID_PRIVATE_KEY); | ||
}, | ||
function() { | ||
vapidHelper.getVapidHeaders(VALID_AUDIENCE, 'Some Random String', VALID_PUBLIC_KEY, VALID_PRIVATE_KEY); | ||
}, | ||
|
@@ -168,9 +180,17 @@ suite('Test Vapid Helpers', function() { | |
function(contentEncoding) { | ||
return vapidHelper.getVapidHeaders(VALID_AUDIENCE, VALID_SUBJECT_URL, VALID_PUBLIC_KEY, VALID_PRIVATE_KEY, contentEncoding); | ||
}, | ||
function(contentEncoding) { | ||
// localhost https: subject; should pass, since we don't throw an error for this, just warn to console | ||
return vapidHelper.getVapidHeaders(VALID_AUDIENCE, WARN_SUBJECT_LOCALHOST_URL, VALID_PUBLIC_KEY, VALID_PRIVATE_KEY, contentEncoding); | ||
}, | ||
function(contentEncoding) { | ||
return vapidHelper.getVapidHeaders(VALID_AUDIENCE, VALID_SUBJECT_MAILTO, VALID_PUBLIC_KEY, VALID_PRIVATE_KEY, contentEncoding); | ||
}, | ||
function(contentEncoding) { | ||
// localhost mailto: subject | ||
return vapidHelper.getVapidHeaders(VALID_AUDIENCE, VALID_SUBJECT_LOCALHOST_MAILTO, VALID_PUBLIC_KEY, VALID_PRIVATE_KEY, contentEncoding); | ||
}, | ||
function(contentEncoding) { | ||
return vapidHelper.getVapidHeaders(VALID_AUDIENCE, VALID_SUBJECT_URL, VALID_PUBLIC_KEY, VALID_PRIVATE_KEY, contentEncoding, VALID_EXPIRATION); | ||
}, | ||
|