Skip to content

Commit 39578d6

Browse files
authored
restrict replaceSecretPlaceholder to cors with allowWhitelist (#4102)
and cleanup spelling
1 parent 22a58d4 commit 39578d6

3 files changed

Lines changed: 50 additions & 4 deletions

File tree

cspell.config.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313
"armv",
1414
"ashishtank",
1515
"autoplay",
16+
"avghumidity",
17+
"avgtemp",
1618
"Autorestart",
1719
"beada",
1820
"Behaviour",
21+
"Beschreibung",
1922
"Binney",
2023
"bluemanos",
2124
"bnitkin",
@@ -111,6 +114,7 @@
111114
"flopp",
112115
"fontawesome",
113116
"fontface",
117+
"forecastday",
114118
"forecastweather",
115119
"fortawesome",
116120
"frameguard",
@@ -186,14 +190,18 @@
186190
"luxon",
187191
"lxsession",
188192
"magicmirror",
193+
"mapbox",
189194
"martingron",
190195
"marvai",
191196
"mastermerge",
192197
"matchtype",
193198
"maxentries",
199+
"maxtemp",
200+
"maxwind",
194201
"Meteo",
195202
"michaelteeuw",
196203
"michmich",
204+
"mintemp",
197205
"Midori",
198206
"mirontoli",
199207
"MISSINGLANG",
@@ -212,7 +220,9 @@
212220
"NEWSFEED",
213221
"newsfeedfetcher",
214222
"newsfetcher",
223+
"newyear",
215224
"newsitems",
225+
"nextdaysrelative",
216226
"nfogal",
217227
"njwilliams",
218228
"nonrepeating",
@@ -239,8 +249,10 @@
239249
"pmin",
240250
"Português",
241251
"PRECIP",
252+
"precips",
242253
"Problema",
243254
"psieg",
255+
"ptype",
244256
"pubdate",
245257
"radokristof",
246258
"rajniszp",
@@ -255,12 +267,14 @@
255267
"Rosso",
256268
"Rothfusz",
257269
"rrule",
270+
"sameorigin",
258271
"savvadam",
259272
"sdetweil",
260273
"searchstr",
261274
"sendheaders",
262275
"serveronly",
263276
"sexualized",
277+
"showend",
264278
"Sitecode",
265279
"skpanagiotis",
266280
"SMHI",
@@ -295,8 +309,11 @@
295309
"timeformat",
296310
"titlereplacestr",
297311
"titlesearchstr",
312+
"TOCTOU",
298313
"todaytemp",
299314
"tomzt",
315+
"totalprecip",
316+
"totalsnow",
300317
"trunc",
301318
"ttlms",
302319
"ukmetoffice",
@@ -317,6 +334,7 @@
317334
"Vorberechnung",
318335
"vppencilsharpener",
319336
"Wallys",
337+
"weatherapi",
320338
"Weatherbit",
321339
"weathercode",
322340
"WEATHERDATA",
@@ -336,6 +354,7 @@
336354
"Woolridge",
337355
"worktree",
338356
"Wsymb",
357+
"xhvw",
339358
"xlarge",
340359
"xmark",
341360
"xrandr",

js/server_functions.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ function getStartup (req, res) {
2222
* @returns {string} the input with real variable content
2323
*/
2424
function replaceSecretPlaceholder (input) {
25-
return input.replaceAll(/\*\*(SECRET_[^*]+)\*\*/g, (match, group) => {
26-
return process.env[group];
27-
});
25+
if (global.config.cors === "allowWhitelist") {
26+
return input.replaceAll(/\*\*(SECRET_[^*]+)\*\*/g, (match, group) => {
27+
return process.env[group];
28+
});
29+
} else {
30+
Log.error("Replacing secrets works only with CORS and `allowWhitelist`, you need to set this in `config.js`, set `cors: allowWhitelist`");
31+
return input;
32+
}
2833
}
2934

3035
/**

tests/unit/functions/server_functions_spec.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ const undici = require("undici");
88
const { cors, getUserAgent, replaceSecretPlaceholder } = require("#server_functions");
99

1010
describe("server_functions tests", () => {
11-
describe("The replaceSecretPlaceholder method", () => {
11+
describe("The replaceSecretPlaceholder method with cors=allowWhitelist", () => {
12+
beforeEach(() => {
13+
global.config = { cors: "allowWhitelist" };
14+
});
15+
1216
it("Calls string without secret placeholder", () => {
1317
const teststring = "test string without secret placeholder";
1418
const result = replaceSecretPlaceholder(teststring);
@@ -25,6 +29,24 @@ describe("server_functions tests", () => {
2529
});
2630
});
2731

32+
describe("The replaceSecretPlaceholder method with cors=allowAll", () => {
33+
beforeEach(() => {
34+
global.config = { cors: "allowAll" };
35+
});
36+
37+
it("Calls string without secret placeholder", () => {
38+
const teststring = "test string without secret placeholder";
39+
const result = replaceSecretPlaceholder(teststring);
40+
expect(result).toBe(teststring);
41+
});
42+
43+
it("Calls string with 2 secret placeholders", () => {
44+
const teststring = "test string with secret1=**SECRET_ONE** and secret2=**SECRET_TWO**";
45+
const result = replaceSecretPlaceholder(teststring);
46+
expect(result).toBe(teststring);
47+
});
48+
});
49+
2850
describe("The cors method", () => {
2951
let fetchSpy;
3052
let fetchResponseHeadersGet;

0 commit comments

Comments
 (0)