fix: сделал loopback origin валидным для push VAPID (#944)
This commit is contained in:
@@ -1,5 +1,15 @@
|
|||||||
const PUSH_SUBSCRIPTIONS_VERSION = 1;
|
const PUSH_SUBSCRIPTIONS_VERSION = 1;
|
||||||
|
|
||||||
|
const isLoopbackHttpOrigin = (value) => {
|
||||||
|
if (typeof value !== 'string') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value.startsWith('http://localhost')
|
||||||
|
|| value.startsWith('http://127.0.0.1')
|
||||||
|
|| value.startsWith('http://[::1]');
|
||||||
|
};
|
||||||
|
|
||||||
export const createPushRuntime = (deps) => {
|
export const createPushRuntime = (deps) => {
|
||||||
const {
|
const {
|
||||||
fsPromises,
|
fsPromises,
|
||||||
@@ -241,7 +251,7 @@ export const createPushRuntime = (deps) => {
|
|||||||
const originEnv = process.env.OPENCHAMBER_PUBLIC_ORIGIN;
|
const originEnv = process.env.OPENCHAMBER_PUBLIC_ORIGIN;
|
||||||
if (typeof originEnv === 'string' && originEnv.trim().length > 0) {
|
if (typeof originEnv === 'string' && originEnv.trim().length > 0) {
|
||||||
const trimmed = originEnv.trim();
|
const trimmed = originEnv.trim();
|
||||||
if (trimmed.startsWith('http://localhost')) {
|
if (isLoopbackHttpOrigin(trimmed)) {
|
||||||
return 'mailto:openchamber@localhost';
|
return 'mailto:openchamber@localhost';
|
||||||
}
|
}
|
||||||
return trimmed;
|
return trimmed;
|
||||||
@@ -252,7 +262,7 @@ export const createPushRuntime = (deps) => {
|
|||||||
const stored = settings?.publicOrigin;
|
const stored = settings?.publicOrigin;
|
||||||
if (typeof stored === 'string' && stored.trim().length > 0) {
|
if (typeof stored === 'string' && stored.trim().length > 0) {
|
||||||
const trimmed = stored.trim();
|
const trimmed = stored.trim();
|
||||||
if (trimmed.startsWith('http://localhost')) {
|
if (isLoopbackHttpOrigin(trimmed)) {
|
||||||
return 'mailto:openchamber@localhost';
|
return 'mailto:openchamber@localhost';
|
||||||
}
|
}
|
||||||
return trimmed;
|
return trimmed;
|
||||||
|
|||||||
Reference in New Issue
Block a user