mirror of
https://gitlab.com/vyla-entertainment/home.git
synced 2026-11-17 07:37:24 -05:00
support artifact redirect hosts and explicit express port binding
This commit is contained in:
4
main.js
4
main.js
@@ -138,7 +138,7 @@ async function start() {
|
|||||||
playerExpressApp.get('*', (req, res) => {
|
playerExpressApp.get('*', (req, res) => {
|
||||||
res.sendFile(path.join(playerDir, 'index.html'));
|
res.sendFile(path.join(playerDir, 'index.html'));
|
||||||
});
|
});
|
||||||
playerExpressServer = playerExpressApp.listen(3001, () => {
|
playerExpressServer = playerExpressApp.listen(3001, '0.0.0.0', () => {
|
||||||
console.log('[DEBUG] Player Express server listening on 3001');
|
console.log('[DEBUG] Player Express server listening on 3001');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -155,7 +155,7 @@ async function start() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const FRONTEND_PORT = 4890;
|
const FRONTEND_PORT = 4890;
|
||||||
expressServer = expressApp.listen(FRONTEND_PORT, () => {
|
expressServer = expressApp.listen(FRONTEND_PORT, '0.0.0.0', () => {
|
||||||
console.log(`[DEBUG] Frontend Express server active at http://localhost:${FRONTEND_PORT}`);
|
console.log(`[DEBUG] Frontend Express server active at http://localhost:${FRONTEND_PORT}`);
|
||||||
sendToTauri('ready', { url: `http://localhost:${FRONTEND_PORT}` });
|
sendToTauri('ready', { url: `http://localhost:${FRONTEND_PORT}` });
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,11 +4,20 @@ const fs = require('fs');
|
|||||||
const GITLAB_GROUP = 'vyla-entertainment';
|
const GITLAB_GROUP = 'vyla-entertainment';
|
||||||
const GITLAB_REPO = 'home';
|
const GITLAB_REPO = 'home';
|
||||||
const RELEASES_API = `https://gitlab.com/api/v4/projects/${GITLAB_GROUP}%2F${GITLAB_REPO}/releases`;
|
const RELEASES_API = `https://gitlab.com/api/v4/projects/${GITLAB_GROUP}%2F${GITLAB_REPO}/releases`;
|
||||||
const ALLOWED_REDIRECT_HOSTS = ['gitlab.com'];
|
|
||||||
|
const ALLOWED_REDIRECT_HOSTS = [
|
||||||
|
'gitlab.com',
|
||||||
|
'storage.googleapis.com'
|
||||||
|
];
|
||||||
|
|
||||||
function isAllowedHost(url) {
|
function isAllowedHost(url) {
|
||||||
try {
|
try {
|
||||||
return ALLOWED_REDIRECT_HOSTS.includes(new URL(url).hostname);
|
const hostname = new URL(url).hostname;
|
||||||
|
return ALLOWED_REDIRECT_HOSTS.includes(hostname) ||
|
||||||
|
hostname.endsWith('.gitlab.com') ||
|
||||||
|
hostname.endsWith('.storage.googleapis.com') ||
|
||||||
|
hostname.endsWith('.amazonaws.com') ||
|
||||||
|
hostname.endsWith('.cloudfront.net');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -80,13 +89,14 @@ class UpdateClient {
|
|||||||
'Accept': 'application/octet-stream'
|
'Accept': 'application/octet-stream'
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.token) {
|
const isGitLabHost = urlObj.hostname === 'gitlab.com' || urlObj.hostname.endsWith('.gitlab.com');
|
||||||
|
if (this.token && isGitLabHost) {
|
||||||
headers['PRIVATE-TOKEN'] = this.token;
|
headers['PRIVATE-TOKEN'] = this.token;
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestOptions = {
|
const requestOptions = {
|
||||||
hostname: urlObj.hostname,
|
hostname: urlObj.hostname,
|
||||||
port: 443,
|
port: urlObj.port || (urlObj.protocol === 'https:' ? 443 : 80),
|
||||||
path: urlObj.pathname + urlObj.search,
|
path: urlObj.pathname + urlObj.search,
|
||||||
headers
|
headers
|
||||||
};
|
};
|
||||||
@@ -94,11 +104,12 @@ class UpdateClient {
|
|||||||
const req = https.get(requestOptions, (res) => {
|
const req = https.get(requestOptions, (res) => {
|
||||||
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
||||||
res.resume();
|
res.resume();
|
||||||
if (!isAllowedHost(res.headers.location)) {
|
const redirectUrl = new URL(res.headers.location, requestUrl).toString();
|
||||||
reject(new Error(`Redirect to disallowed host: ${res.headers.location}`));
|
if (!isAllowedHost(redirectUrl)) {
|
||||||
|
reject(new Error(`Redirect to disallowed host: ${redirectUrl}`));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
doRequest(res.headers.location, redirectCount + 1);
|
doRequest(redirectUrl, redirectCount + 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,13 +171,14 @@ class UpdateClient {
|
|||||||
'Accept': 'application/octet-stream'
|
'Accept': 'application/octet-stream'
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.token) {
|
const isGitLabHost = urlObj.hostname === 'gitlab.com' || urlObj.hostname.endsWith('.gitlab.com');
|
||||||
|
if (this.token && isGitLabHost) {
|
||||||
headers['PRIVATE-TOKEN'] = this.token;
|
headers['PRIVATE-TOKEN'] = this.token;
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestOptions = {
|
const requestOptions = {
|
||||||
hostname: urlObj.hostname,
|
hostname: urlObj.hostname,
|
||||||
port: 443,
|
port: urlObj.port || (urlObj.protocol === 'https:' ? 443 : 80),
|
||||||
path: urlObj.pathname + urlObj.search,
|
path: urlObj.pathname + urlObj.search,
|
||||||
headers
|
headers
|
||||||
};
|
};
|
||||||
@@ -174,7 +186,12 @@ class UpdateClient {
|
|||||||
const req = https.get(requestOptions, (res) => {
|
const req = https.get(requestOptions, (res) => {
|
||||||
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
||||||
res.resume();
|
res.resume();
|
||||||
doRequest(res.headers.location, redirectCount + 1);
|
const redirectUrl = new URL(res.headers.location, requestUrl).toString();
|
||||||
|
if (!isAllowedHost(redirectUrl)) {
|
||||||
|
reject(new Error(`Redirect to disallowed host: ${redirectUrl}`));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
doRequest(redirectUrl, redirectCount + 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user