Skip to content

Conversation

@fangsmile
Copy link
Contributor

[中文版模板 / Chinese template]

🤔 This is a ...

  • New feature
  • Bug fix
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Refactoring
  • Update dependency
  • Code style optimization
  • Test Case
  • Branch merge
  • Site / documentation update
  • Demo update
  • Workflow
  • Chore
  • Release
  • Other (about what?)

🔗 Related issue link

💡 Background and solution

📝 Changelog

Language Changelog
🇺🇸 English
🇨🇳 Chinese

☑️ Self-Check before Merge

⚠️ Please check all items below before requesting a reviewing. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

🚀 Summary

copilot:summary

🔍 Walkthrough

copilot:walkthrough

const departments = ['研发部', '市场部', '销售部', '人事部', '财务部', '设计部', '客服部', '运营部'];

return Array.from(new Array(count)).map((_, i) => {
const salary = Math.floor(5000 + Math.random() * 15000);

Check failure

Code scanning / CodeQL

Insecure randomness High

This uses a cryptographically insecure random number generated at
Math.random()
in a security context.

Copilot Autofix

AI 2 months ago

To fix the issue, we should replace the use of Math.random() with a cryptographically secure random number generator when generating demo data. In Node.js, we use the crypto module—specifically, crypto.randomInt for generating secure random integers. For lines in generateDemoData—specifically line 15, line 16, and line 26—replace Math.random-based expressions with calls to crypto.randomInt. We need to import the crypto module in the file. Convert usages as:

  • Math.floor(5000 + Math.random() * 15000)crypto.randomInt(5000, 20000)
  • Math.floor(10000 + Math.random() * 90000)crypto.randomInt(10000, 100000)
  • Math.floor(Math.random() * (10 - 5 + 1)) + 5crypto.randomInt(5, 11)

Edit the demo data generation function accordingly and add the required import for crypto.

Suggested changeset 1
packages/vtable-plugins/demo/filter/bug.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/vtable-plugins/demo/filter/bug.ts b/packages/vtable-plugins/demo/filter/bug.ts
--- a/packages/vtable-plugins/demo/filter/bug.ts
+++ b/packages/vtable-plugins/demo/filter/bug.ts
@@ -1,6 +1,7 @@
 import * as VTable from '@visactor/vtable';
 import { bindDebugTool } from '@visactor/vtable/es/scenegraph/debug-tool';
 import { FilterPlugin } from '../../src/filter';
+import * as crypto from 'crypto';
 const CONTAINER_ID = 'vTable';
 
 /**
@@ -12,8 +13,8 @@
   const departments = ['研发部', '市场部', '销售部', '人事部', '财务部', '设计部', '客服部', '运营部'];
 
   return Array.from(new Array(count)).map((_, i) => {
-    const salary = Math.floor(5000 + Math.random() * 15000);
-    const sales = Math.floor(10000 + Math.random() * 90000);
+    const salary = crypto.randomInt(5000, 20000);
+    const sales = crypto.randomInt(10000, 100000);
     const isSelected = i % 3 === 0;
     const option = i === 1;
 
@@ -23,7 +24,7 @@
       gender: i % 2 === 0 ? '男' : '女',
       salary,
       sales,
-      seniority: Math.floor(Math.random() * (10 - 5 + 1)) + 5,
+      seniority: crypto.randomInt(5, 11), // 5 to 10 inclusive
       isFullTime: i % 5 !== 0,
       department: departments[i % departments.length],
       favoriteColor: colors[i % colors.length],
EOF
@@ -1,6 +1,7 @@
import * as VTable from '@visactor/vtable';
import { bindDebugTool } from '@visactor/vtable/es/scenegraph/debug-tool';
import { FilterPlugin } from '../../src/filter';
import * as crypto from 'crypto';
const CONTAINER_ID = 'vTable';

/**
@@ -12,8 +13,8 @@
const departments = ['研发部', '市场部', '销售部', '人事部', '财务部', '设计部', '客服部', '运营部'];

return Array.from(new Array(count)).map((_, i) => {
const salary = Math.floor(5000 + Math.random() * 15000);
const sales = Math.floor(10000 + Math.random() * 90000);
const salary = crypto.randomInt(5000, 20000);
const sales = crypto.randomInt(10000, 100000);
const isSelected = i % 3 === 0;
const option = i === 1;

@@ -23,7 +24,7 @@
gender: i % 2 === 0 ? '男' : '女',
salary,
sales,
seniority: Math.floor(Math.random() * (10 - 5 + 1)) + 5,
seniority: crypto.randomInt(5, 11), // 5 to 10 inclusive
isFullTime: i % 5 !== 0,
department: departments[i % departments.length],
favoriteColor: colors[i % colors.length],
Copilot is powered by AI and may make mistakes. Always verify output.
@github-actions github-actions bot added the chore label Nov 13, 2025
@fangsmile fangsmile merged commit 02fe69c into develop Nov 18, 2025
6 of 8 checks passed
@fangsmile fangsmile deleted the fix/filter-plugins branch November 18, 2025 03:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants