snakeia-server 1.1.4-2 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,7 +8,7 @@ A server for my [SnakeIA](https://github.com/Eliastik/snakeia) game, written in
8
8
 
9
9
  ## About this server
10
10
 
11
- * Version 1.1.4.2 (6/18/2025)
11
+ * Version 1.1.5 (6/18/2025)
12
12
  * Made in France by Eliastik - [eliastiksofts.com](http://eliastiksofts.com) - Contact : [eliastiksofts.com/contact](http://eliastiksofts.com/contact)
13
13
  * License: GNU GPLv3 (see LICENCE.txt file)
14
14
 
@@ -74,7 +74,7 @@ You can create another configuration file in the **config** directory named **lo
74
74
  ````
75
75
  {
76
76
  "ServerConfig": {
77
- "version": "1.1.4.2", // The server version
77
+ "version": "1.1.5", // The server version
78
78
  "port": 3000, // The port where the server runs
79
79
  "proxyMode": false, // Sets this value to true if your server is behind a proxy - defaults to false
80
80
  "numberOfProxies": 1, // Sets the number of reverse proxies in front of the server. Default to 1. See: https://expressjs.com/en/guide/behind-proxies.html / https://express-rate-limit.mintlify.app/guides/troubleshooting-proxy-issues
@@ -120,6 +120,9 @@ You can create another configuration file in the **config** directory named **lo
120
120
 
121
121
  ## Changelog
122
122
 
123
+ * Version 1.1.5 (6/18/2025):
124
+ - Fixed "Error: invalid CSRF token" occurring during certain actions in the administrator panel
125
+
123
126
  * Version 1.1.4.2 (6/18/2025):
124
127
  - Updated dependencies
125
128
 
@@ -185,7 +188,7 @@ Un serveur pour mon jeu [SnakeIA](https://github.com/Eliastik/snakeia), écrit e
185
188
 
186
189
  ## À propos de ce serveur
187
190
 
188
- * Version 1.1.4.2 (18/06/2025)
191
+ * Version 1.1.5 (18/06/2025)
189
192
  * Made in France by Eliastik - [eliastiksofts.com](http://eliastiksofts.com) - Contact : [eliastiksofts.com/contact](http://eliastiksofts.com/contact)
190
193
  * Licence : GNU GPLv3 (voir le fichier LICENCE.txt)
191
194
 
@@ -251,7 +254,7 @@ Vous pouvez créer un fichier de configuration **local.json** dans le dossier **
251
254
  ````
252
255
  {
253
256
  "ServerConfig": {
254
- "version": "1.1.4.2", // La version du serveur
257
+ "version": "1.1.5", // La version du serveur
255
258
  "port": 3000, // Le port sur lequel lancer le server
256
259
  "proxyMode": false, // Mettez à true si votre serveur est derrière un proxy - par défaut false
257
260
  "numberOfProxies": 1, // Configure le nombre de proxies devant votre serveur. Par défaut 1. Voir : https://expressjs.com/en/guide/behind-proxies.html / https://express-rate-limit.mintlify.app/guides/troubleshooting-proxy-issues
@@ -297,6 +300,9 @@ Vous pouvez créer un fichier de configuration **local.json** dans le dossier **
297
300
 
298
301
  ## Journal des changements
299
302
 
303
+ * Version 1.1.5 (18/06/2025) :
304
+ - Correction de l’erreur "Error: invalid CSRF token" lors de certaines actions dans le panneau d’administration
305
+
300
306
  * Version 1.1.4.2 (18/06/2025) :
301
307
  - Mise à jour des dépendences
302
308
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "ServerConfig": {
3
- "version": "1.1.4.2",
3
+ "version": "1.1.5",
4
4
  "port": 3000,
5
5
  "proxyMode": false,
6
6
  "numberOfProxies": 1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "snakeia-server",
3
- "version": "1.1.4-2",
3
+ "version": "1.1.5",
4
4
  "description": "Server for multiplaying in SnakeIA (https://github.com/Eliastik/snakeia)",
5
5
  "main": "server.js",
6
6
  "scripts": {
package/server.js CHANGED
@@ -96,6 +96,7 @@ i18n.configure({
96
96
 
97
97
  // Game modules
98
98
  const snakeia = require("snakeia");
99
+ const { randomUUID } = require("crypto");
99
100
  const Snake = snakeia.Snake;
100
101
  const Grid = snakeia.Grid;
101
102
  const GameConstants = snakeia.GameConstants;
@@ -908,7 +909,8 @@ app.use(i18n.init);
908
909
  // Rate limiter
909
910
  app.use("/authentication", rateLimit({
910
911
  windowMs: config.authentWindowMs,
911
- max: config.authentMaxRequest
912
+ max: config.authentMaxRequest,
913
+ validate: { trustProxy: false }
912
914
  }));
913
915
 
914
916
  // IP ban
@@ -1168,8 +1170,16 @@ function verifyFormAuthenticationAdmin(body) {
1168
1170
  }
1169
1171
 
1170
1172
  const csrfSecret = generateRandomJsonWebTokenSecretKey(jsonWebTokenSecretKeyAdmin);
1171
- const { doubleCsrfProtection, generateToken } = doubleCsrf({
1173
+ const { doubleCsrfProtection, generateCsrfToken } = doubleCsrf({
1172
1174
  getSecret: () => csrfSecret,
1175
+ getSessionIdentifier: (req) => req.cookies.tokenAdmin || randomUUID(),
1176
+ getCsrfTokenFromRequest: (req) => {
1177
+ return (
1178
+ req.headers["x-csrf-token"] ||
1179
+ req.body?._csrf ||
1180
+ req.query?._csrf
1181
+ );
1182
+ },
1173
1183
  cookieName: productionMode ? "__Host-snakeia-server.x-csrf-token" : "snakeia-server.x-csrf-token",
1174
1184
  cookieOptions: {
1175
1185
  sameSite: productionMode ? "strict" : "lax",
@@ -1206,7 +1216,7 @@ app.get("/admin", doubleCsrfProtection, function(req, res) {
1206
1216
  games: games,
1207
1217
  io: io,
1208
1218
  config: config,
1209
- csrfToken: generateToken(req, res, true),
1219
+ csrfToken: generateCsrfToken(req, res, { overwrite: true, validateOnReuse: true }),
1210
1220
  serverLog: logFile,
1211
1221
  errorLog: errorLogFile,
1212
1222
  getIPSocketIO: getIPSocketIO
@@ -1311,7 +1321,8 @@ app.use(function (err, req, res, next) {
1311
1321
 
1312
1322
  const adminRateLimiter = rateLimit({
1313
1323
  windowMs: config.authentWindowMs,
1314
- max: config.authentMaxRequest
1324
+ max: config.authentMaxRequest,
1325
+ validate: { trustProxy: false }
1315
1326
  });
1316
1327
 
1317
1328
  app.post("/admin", adminRateLimiter, function(req, res) {