Evaluate calculator and goal tree formulas without eval
The production CSP forbids unsafe-eval, so the Function() call behind both tools threw, every result came back empty and the calculator save and update buttons stayed disabled in production. Dev worked because Vite sends no CSP. Both now reuse the eval-free parser of the table formula engine, and a test fails if client code evaluates strings again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
337e08caea
commit
08e28ee70d
5 changed files with 33 additions and 14 deletions
|
|
@ -1,6 +1,6 @@
|
|||
// Rôle : vérifie les en-têtes de cache du serveur Node sur des fichiers de production représentatifs.
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { mkdir, mkdtemp, readdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
import assert from "node:assert/strict";
|
||||
|
|
@ -122,3 +122,14 @@ test("every response carries the security headers and the CSP allows only the in
|
|||
assert.ok(headers.get("referrer-policy"));
|
||||
}
|
||||
});
|
||||
|
||||
test("client code never evaluates strings, since the production CSP forbids unsafe-eval", async () => {
|
||||
const entries = await readdir("website/src", { recursive: true, withFileTypes: true });
|
||||
const sources = entries.filter((entry) => entry.isFile() && /\.(jsx?|mjs)$/.test(entry.name));
|
||||
assert.ok(sources.length > 0);
|
||||
for (const entry of sources) {
|
||||
const path = join(entry.parentPath, entry.name);
|
||||
const source = await readFile(path, "utf8");
|
||||
assert.doesNotMatch(source, /(?<![\w.])(?:new\s+)?Function\s*\(|(?<![\w.])eval\s*\(/, path);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -524,6 +524,14 @@ test("calculator helpers evaluate formulas and preserve tree order", () => {
|
|||
assert.equal(calculateExpression("2 + 3 * 4"), 14);
|
||||
assert.equal(calculateExpression("base / 2", 10), 5);
|
||||
assert.equal(calculateExpression("window.alert(1)"), null);
|
||||
assert.equal(calculateExpression("(2 + 3) * -2"), -10);
|
||||
assert.equal(calculateExpression("base * 3", -5), -15);
|
||||
assert.equal(calculateExpression("1,5 * 2"), 3);
|
||||
assert.equal(calculateExpression("10 / 0"), null);
|
||||
assert.equal(calculateExpression("2 (3)"), null);
|
||||
assert.equal(calculateExpression("1.2.3"), null);
|
||||
assert.equal(calculateExpression("(1 + 2"), null);
|
||||
assert.equal(calculateExpression("base * 2"), null);
|
||||
assert.equal(calculateRemainingValue("base * 8", "20", 10), 60);
|
||||
assert.equal(calculateRemainingValue("80", "20,5"), 59.5);
|
||||
assert.equal(calculateRemainingValue("80", "invalid"), null);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue