From 6a620f10d2af80935f15943abdd856304abd1a61 Mon Sep 17 00:00:00 2001 From: WardPearce Date: Sat, 25 Jan 2025 12:06:50 +1300 Subject: [PATCH] Minor improvements to proxy header handling --- materialious/android/app/build.gradle | 4 ++-- materialious/electron/package.json | 2 +- materialious/package.json | 2 +- materialious/static/nodejs-android/index.js | 15 ++++++++------- update_versions.py | 2 +- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/materialious/android/app/build.gradle b/materialious/android/app/build.gradle index 9e47c014..2a245ad0 100644 --- a/materialious/android/app/build.gradle +++ b/materialious/android/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "us.materialio.app" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 84 - versionName "1.7.2" + versionCode 85 + versionName "1.7.3" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" aaptOptions { // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps. diff --git a/materialious/electron/package.json b/materialious/electron/package.json index c64d7999..f65c2a02 100644 --- a/materialious/electron/package.json +++ b/materialious/electron/package.json @@ -1,6 +1,6 @@ { "name": "Materialious", - "version": "1.7.2", + "version": "1.7.3", "description": "Modern material design for Invidious.", "author": { "name": "Ward Pearce", diff --git a/materialious/package.json b/materialious/package.json index a0ab62f1..9779cf2a 100644 --- a/materialious/package.json +++ b/materialious/package.json @@ -1,6 +1,6 @@ { "name": "materialious", - "version": "1.7.2", + "version": "1.7.3", "private": true, "scripts": { "dev": "vite dev", diff --git a/materialious/static/nodejs-android/index.js b/materialious/static/nodejs-android/index.js index bef64195..bed472ea 100644 --- a/materialious/static/nodejs-android/index.js +++ b/materialious/static/nodejs-android/index.js @@ -4,10 +4,9 @@ const https = require('https'); const HOST = 'localhost'; const PORT = 3000; const MAX_REDIRECTS = 5; -const ORIGIN = `https://${HOST}`; function setCorsHeaders(res) { - res.setHeader('Access-Control-Allow-Origin', ORIGIN); + res.setHeader('Access-Control-Allow-Origin', '*'); res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS'); res.setHeader('Access-Control-Allow-Headers', '*'); res.setHeader('Access-Control-Allow-Credentials', 'true'); @@ -17,6 +16,7 @@ function fetchWithRedirects(targetUrl, options, redirectCount = 0) { return new Promise((resolve, reject) => { const httpClient = targetUrl.protocol.startsWith('https') ? https : http; + const req = httpClient.request(targetUrl, options, (res) => { if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) { if (redirectCount >= MAX_REDIRECTS) { @@ -78,10 +78,11 @@ const server = http.createServer(async (req, res) => { req.on('end', async () => { const options = { method: req.method, - headers: { - ...req.headers, - host: parsedTarget.hostname, // Ensure correct host header - } + headers: Object.fromEntries( + Object.entries(req.headers).filter(([key]) => ![ + 'host', 'origin', 'referer', 'x-forwarded-for', 'x-requested-with' + ].includes(key.toLowerCase())) + ) }; // For POST and PUT methods, pass the body to the outgoing request @@ -100,7 +101,7 @@ const server = http.createServer(async (req, res) => { res.writeHead(proxyRes.statusCode, { ...proxyRes.headers, - 'Access-Control-Allow-Origin': ORIGIN, + 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', 'Access-Control-Allow-Headers': '*', 'Access-Control-Allow-Credentials': 'true', diff --git a/update_versions.py b/update_versions.py index 70a65341..d5935414 100644 --- a/update_versions.py +++ b/update_versions.py @@ -5,7 +5,7 @@ import json import os import re -LATEST_VERSION = "1.7.2" +LATEST_VERSION = "1.7.3" WORKING_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "materialious") ROOT_PACKAGE = os.path.join(WORKING_DIR, "package.json")