mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-10-30 17:27:09 +00:00
fix(lint): give randomness guidance for crypto values (#3659)
Builds on #1729 in the extracted lint package. Co-authored-by: AGRO-CODEX <brstopo@gmail.com>
This commit is contained in:
co-authored by
AGRO-CODEX
parent
29efd5dfa8
commit
0ad9c700ac
@@ -601,6 +601,25 @@ describe("core rules", () => {
|
||||
});
|
||||
|
||||
describe("non_deterministic_code", () => {
|
||||
it("gives randomness guidance for crypto and clock guidance for wall time", async () => {
|
||||
const result = await lintHyperframeHtml(`<html><body>
|
||||
<div data-composition-id="c1" data-width="1920" data-height="1080"></div>
|
||||
<script>
|
||||
crypto.getRandomValues(new Uint32Array(1));
|
||||
Date.now();
|
||||
window.__timelines = { c1: gsap.timeline({ paused: true }) };
|
||||
</script>
|
||||
</body></html>`);
|
||||
const crypto = result.findings.find((finding) =>
|
||||
finding.message.includes("crypto.getRandomValues"),
|
||||
);
|
||||
const clock = result.findings.find((finding) => finding.message.includes("Date.now"));
|
||||
expect(crypto).toMatchObject({ code: "non_deterministic_code", severity: "error" });
|
||||
expect(crypto?.fixHint).toContain("seeded PRNG");
|
||||
expect(crypto?.fixHint).not.toContain("time-dependent");
|
||||
expect(clock?.fixHint).toContain("wall-clock time");
|
||||
});
|
||||
|
||||
it("detects Math.random() in script content", async () => {
|
||||
const html = `
|
||||
<html><body>
|
||||
|
||||
@@ -478,7 +478,7 @@ export const coreRules: Array<(ctx: LintContext) => HyperframeLintFinding[]> = [
|
||||
{
|
||||
pattern: /crypto\.getRandomValues\s*\(/,
|
||||
label: "crypto.getRandomValues()",
|
||||
hint: "Remove time-dependent code. Use a seeded PRNG for deterministic renders.",
|
||||
hint: "Use a seeded PRNG (e.g. a simple mulberry32) so renders are deterministic across frames.",
|
||||
},
|
||||
{
|
||||
pattern: /gsap\.utils\.random\s*\(/,
|
||||
|
||||
Reference in New Issue
Block a user