Skip to content

Commit

Permalink
Fix validation error of protocol not being returned (#843)
Browse files Browse the repository at this point in the history
Fixes #830
  • Loading branch information
glasgio authored Sep 1, 2023
1 parent bb168da commit 15dc7b3
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/vapid-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,20 @@ function validateSubject(subject) {
+ 'mailto: address. ' + subject);
}

let subjectParseResult = null;
try {
const subjectParseResult = new URL(subject);
if (!['https:', 'mailto:'].includes(subjectParseResult.protocol)) {
throw new Error('Vapid subject is not an https: or mailto: URL. ' + subject);
}
if (subjectParseResult.hostname === 'localhost') {
console.warn('Vapid subject points to a localhost web URI, which is unsupported by '
+ 'Apple\'s push notification server and will result in a BadJwtToken error when '
+ 'sending notifications.');
}
subjectParseResult = new URL(subject);
} catch (err) {
throw new Error('Vapid subject is not a valid URL. ' + subject);
}
if (!['https:', 'mailto:'].includes(subjectParseResult.protocol)) {
throw new Error('Vapid subject is not an https: or mailto: URL. ' + subject);
}
if (subjectParseResult.hostname === 'localhost') {
console.warn('Vapid subject points to a localhost web URI, which is unsupported by '
+ 'Apple\'s push notification server and will result in a BadJwtToken error when '
+ 'sending notifications.');
}
}

function validatePublicKey(publicKey) {
Expand Down

0 comments on commit 15dc7b3

Please sign in to comment.