Skip to content

Commit a93eed5

Browse files
committed
strip protocol from host, fix CSRF for transimission with missing session id
1 parent bdcb05e commit a93eed5

File tree

13 files changed

+169
-45
lines changed

13 files changed

+169
-45
lines changed

backend/src/routes/adguard.route.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ const validateItemId = (req: Request): string => {
5353
const getBaseUrl = (req: Request): string => {
5454
const itemId = validateItemId(req);
5555
const connectionInfo = getItemConnectionInfo(itemId);
56-
const host = connectionInfo.host || 'localhost';
56+
57+
// Clean the host to remove any protocol prefix
58+
let host = connectionInfo.host || 'localhost';
59+
host = host.replace(/^https?:\/\//, '');
60+
host = host.replace(/\/+$/, '');
61+
5762
const port = connectionInfo.port || '3000';
5863
const ssl = connectionInfo.ssl || false;
5964
const protocol = ssl ? 'https' : 'http';

backend/src/routes/deluge.route.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ const validateItemId = (req: Request): string => {
8989
const getBaseUrl = (req: Request): string => {
9090
const itemId = validateItemId(req);
9191
const connectionInfo = getItemConnectionInfo(itemId);
92-
const host = connectionInfo.host || 'localhost';
92+
93+
// Clean the host to remove any protocol prefix
94+
let host = connectionInfo.host || 'localhost';
95+
host = host.replace(/^https?:\/\//, '');
96+
host = host.replace(/\/+$/, '');
97+
9398
const port = connectionInfo.port || '8112';
9499
const ssl = connectionInfo.ssl || false;
95100
const protocol = ssl ? 'https' : 'http';

backend/src/routes/jellyfin.route.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,14 @@ jellyfinRoute.get('/sessions', async (req: Request, res: Response) => {
7272

7373
console.log('Jellyfin sessions request');
7474

75+
// Clean the host to remove any protocol prefix
76+
let cleanHost = host;
77+
cleanHost = cleanHost.replace(/^https?:\/\//, '');
78+
cleanHost = cleanHost.replace(/\/+$/, '');
79+
7580
const protocol = ssl ? 'https' : 'http';
7681
const actualPort = port || '8096';
77-
const baseUrl = `${protocol}://${host}:${actualPort}`;
82+
const baseUrl = `${protocol}://${cleanHost}:${actualPort}`;
7883
const sessionsUrl = `${baseUrl}/Sessions`;
7984

8085
const httpModule = ssl ? https : http;
@@ -183,9 +188,14 @@ jellyfinRoute.get('/library-stats', async (req: Request, res: Response) => {
183188

184189
console.log('Jellyfin library stats request');
185190

191+
// Clean the host to remove any protocol prefix
192+
let cleanHost = host;
193+
cleanHost = cleanHost.replace(/^https?:\/\//, '');
194+
cleanHost = cleanHost.replace(/\/+$/, '');
195+
186196
const protocol = ssl ? 'https' : 'http';
187197
const actualPort = port || '8096';
188-
const baseUrl = `${protocol}://${host}:${actualPort}`;
198+
const baseUrl = `${protocol}://${cleanHost}:${actualPort}`;
189199

190200
const httpModule = ssl ? https : http;
191201

backend/src/routes/jellyseerr.route.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ const validateItemId = (req: Request): string => {
2424
const getBaseUrl = (req: Request): string => {
2525
const itemId = validateItemId(req);
2626
const connectionInfo = getItemConnectionInfo(itemId);
27-
const host = connectionInfo.host || 'localhost';
27+
28+
// Clean the host to remove any protocol prefix
29+
let host = connectionInfo.host || 'localhost';
30+
host = host.replace(/^https?:\/\//, '');
31+
host = host.replace(/\/+$/, '');
32+
2833
const port = connectionInfo.port || '5055';
2934
const ssl = connectionInfo.ssl || false;
3035
const protocol = ssl ? 'https' : 'http';

backend/src/routes/pihole-v6.route.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,12 @@ const validateItemId = (req: Request): string => {
118118
const getBaseUrl = (req: Request): string => {
119119
const itemId = validateItemId(req);
120120
const connectionInfo = getItemConnectionInfo(itemId);
121-
const host = connectionInfo.host || 'localhost';
121+
122+
// Clean the host to remove any protocol prefix
123+
let host = connectionInfo.host || 'localhost';
124+
host = host.replace(/^https?:\/\//, '');
125+
host = host.replace(/\/+$/, '');
126+
122127
const port = connectionInfo.port || '80';
123128
const ssl = connectionInfo.ssl || false;
124129
const protocol = ssl ? 'https' : 'http';

backend/src/routes/pihole.route.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ const validateItemId = (req: Request): string => {
2525
const getBaseUrl = (req: Request): string => {
2626
const itemId = validateItemId(req);
2727
const connectionInfo = getItemConnectionInfo(itemId);
28-
const host = connectionInfo.host || 'localhost';
28+
29+
// Clean the host to remove any protocol prefix
30+
let host = connectionInfo.host || 'localhost';
31+
host = host.replace(/^https?:\/\//, '');
32+
host = host.replace(/\/+$/, '');
33+
2934
const port = connectionInfo.port || '80';
3035
const ssl = connectionInfo.ssl || false;
3136
const protocol = ssl ? 'https' : 'http';

backend/src/routes/qbittorrent.route.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ const getBaseUrl = (req: Request): string => {
3030
}
3131

3232
const connectionInfo = getItemConnectionInfo(itemId);
33-
const host = connectionInfo.host || 'localhost';
33+
34+
// Clean the host to remove any protocol prefix
35+
let host = connectionInfo.host || 'localhost';
36+
host = host.replace(/^https?:\/\//, '');
37+
host = host.replace(/\/+$/, '');
38+
3439
const port = connectionInfo.port || '8080';
3540
const ssl = connectionInfo.ssl || false;
3641
const protocol = ssl ? 'https' : 'http';

backend/src/routes/radarr.route.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ const validateItemId = (req: Request): string => {
2424
const getBaseUrl = (req: Request): string => {
2525
const itemId = validateItemId(req);
2626
const connectionInfo = getItemConnectionInfo(itemId);
27-
const host = connectionInfo.host || 'localhost';
27+
28+
// Clean the host to remove any protocol prefix
29+
let host = connectionInfo.host || 'localhost';
30+
host = host.replace(/^https?:\/\//, '');
31+
host = host.replace(/\/+$/, '');
32+
2833
const port = connectionInfo.port || '7878';
2934
const ssl = connectionInfo.ssl || false;
3035
const protocol = ssl ? 'https' : 'http';

backend/src/routes/sabnzbd.route.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ const getBaseUrl = (req: Request): string => {
2727
}
2828

2929
const connectionInfo = getItemConnectionInfo(itemId);
30-
const host = connectionInfo.host || 'localhost';
30+
31+
// Clean the host to remove any protocol prefix
32+
let host = connectionInfo.host || 'localhost';
33+
// Remove http:// or https:// if present
34+
host = host.replace(/^https?:\/\//, '');
35+
// Remove any trailing slashes
36+
host = host.replace(/\/+$/, '');
37+
3138
const port = connectionInfo.port || '8080';
3239
const ssl = connectionInfo.ssl || false;
3340
const protocol = ssl ? 'https' : 'http';

backend/src/routes/sonarr.route.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ const validateItemId = (req: Request): string => {
2424
const getBaseUrl = (req: Request): string => {
2525
const itemId = validateItemId(req);
2626
const connectionInfo = getItemConnectionInfo(itemId);
27-
const host = connectionInfo.host || 'localhost';
27+
28+
// Clean the host to remove any protocol prefix
29+
let host = connectionInfo.host || 'localhost';
30+
host = host.replace(/^https?:\/\//, '');
31+
host = host.replace(/\/+$/, '');
32+
2833
const port = connectionInfo.port || '8989';
2934
const ssl = connectionInfo.ssl || false;
3035
const protocol = ssl ? 'https' : 'http';

0 commit comments

Comments
 (0)