-
Notifications
You must be signed in to change notification settings - Fork 437
Fix/filter plugins #4711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/filter plugins #4711
Conversation
fix: prevent filter plugin crash when input data is missing
fix: adjust filter menu to correct position
…nput fix: reset filter when setFilterState receives empty params
| 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
Math.random()
Show autofix suggestion
Hide autofix suggestion
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)) + 5→crypto.randomInt(5, 11)
Edit the demo data generation function accordingly and add the required import for crypto.
-
Copy modified line R4 -
Copy modified lines R16-R17 -
Copy modified line R27
| @@ -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], |
[中文版模板 / Chinese template]
🤔 This is a ...
🔗 Related issue link
💡 Background and solution
📝 Changelog
☑️ Self-Check before Merge
🚀 Summary
copilot:summary
🔍 Walkthrough
copilot:walkthrough