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

Fix validation error of protocol not beeing returned #843

Merged
merged 4 commits into from
Sep 1, 2023
Merged
Changes from 3 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
16 changes: 8 additions & 8 deletions src/vapid-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@
}

try {
const subjectParseResult = new URL(subject);

Check failure on line 79 in src/vapid-helper.js

View workflow job for this annotation

GitHub Actions / Tests and linting (ubuntu-latest, 16)

'subjectParseResult' is assigned a value but never used

Check failure on line 79 in src/vapid-helper.js

View workflow job for this annotation

GitHub Actions / Tests and linting (ubuntu-latest, lts/*)

'subjectParseResult' is assigned a value but never used

Check failure on line 79 in src/vapid-helper.js

View workflow job for this annotation

GitHub Actions / Tests and linting (ubuntu-latest, 20)

'subjectParseResult' is assigned a value but never used
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.');
}
} catch (err) {
throw new Error('Vapid subject is not a valid URL. ' + subject);
}
marco-c marked this conversation as resolved.
Show resolved Hide resolved
if (!['https:', 'mailto:'].includes(subjectParseResult.protocol)) {

Check failure on line 83 in src/vapid-helper.js

View workflow job for this annotation

GitHub Actions / Tests and linting (ubuntu-latest, 16)

'subjectParseResult' is not defined

Check failure on line 83 in src/vapid-helper.js

View workflow job for this annotation

GitHub Actions / Tests and linting (ubuntu-latest, lts/*)

'subjectParseResult' is not defined

Check failure on line 83 in src/vapid-helper.js

View workflow job for this annotation

GitHub Actions / Tests and linting (ubuntu-latest, 20)

'subjectParseResult' is not defined
throw new Error('Vapid subject is not an https: or mailto: URL. ' + subject);
}
if (subjectParseResult.hostname === 'localhost') {

Check failure on line 86 in src/vapid-helper.js

View workflow job for this annotation

GitHub Actions / Tests and linting (ubuntu-latest, 16)

'subjectParseResult' is not defined

Check failure on line 86 in src/vapid-helper.js

View workflow job for this annotation

GitHub Actions / Tests and linting (ubuntu-latest, lts/*)

'subjectParseResult' is not defined

Check failure on line 86 in src/vapid-helper.js

View workflow job for this annotation

GitHub Actions / Tests and linting (ubuntu-latest, 20)

'subjectParseResult' is not defined
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
Loading