-
Notifications
You must be signed in to change notification settings - Fork 423
feat: vtable-sheet support excel multiple sheets #4822
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
Conversation
| // 自动更新表格 | ||
| if (options.autoTable && this._tableInstance) { | ||
| if (options.autoColumns) { | ||
| this._tableInstance.updateOption({ |
Check failure
Code scanning / CodeQL
DOM text reinterpreted as HTML High
DOM text
DOM text
DOM text
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 20 days ago
General Approach:
To resolve the identified issue, the code should sanitize untrusted HTML before parsing it with DOMParser. This can be done by using a sanitization library (such as dompurify if available) to ensure only safe markup (or, more conservatively, only tables with no scripts/etc.) is parsed. This ensures that even if untrusted input contains scripts or dangerous tags, they are stripped or neutralized before parsing, preventing XSS regardless of later usage.
Detailed Remedy:
- In
ExcelImportPlugin._parseHTMLString, sanitize thetextinput beforeDOMParser.parseFromString, usingDOMPurify.sanitizeor equivalent. - Add an import for a standard HTML sanitization library (
dompurify) at the top of the filepackages/vtable-plugins/src/excel-import.ts. - Use
DOMPurify.sanitize(text, { ALLOWED_TAGS: ['table', 'thead', 'tbody', 'tfoot', 'tr', 'th', 'td'] })to only allow table-related markup. - Update all
parseFromString(text, 'text/html')to use the sanitized string.
Required Changes:
- File:
packages/vtable-plugins/src/excel-import.ts- Add import for
dompurify(asDOMPurify). - Modify
_parseHTMLStringto sanitizetextbefore parsing.
- Add import for
-
Copy modified line R7 -
Copy modified lines R655-R656 -
Copy modified line R658
| @@ -4,7 +4,7 @@ | ||
| import { importExcelMultipleSheets, importCsvFile } from './excel-import/excel'; | ||
| import { applyImportToVTableSheet } from './excel-import/vtable-sheet'; | ||
| import type { ExcelImportOptions, ImportResult, MultiSheetImportResult } from './excel-import/types'; | ||
|
|
||
| import DOMPurify from 'dompurify'; | ||
| export type { ExcelImportOptions, ImportResult, MultiSheetImportResult, SheetData } from './excel-import/types'; | ||
|
|
||
| /** | ||
| @@ -652,8 +652,10 @@ | ||
| * 解析HTML字符串 | ||
| */ | ||
| private async _parseHTMLString(text: string, options: ExcelImportOptions): Promise<ImportResult> { | ||
| // Sanitize HTML to avoid XSS issues from untrusted input | ||
| const sanitized = DOMPurify.sanitize(text, { ALLOWED_TAGS: ['table', 'thead', 'tbody', 'tfoot', 'tr', 'th', 'td'], ALLOWED_ATTR: [] }); | ||
| const parser = new DOMParser(); | ||
| const doc = parser.parseFromString(text, 'text/html'); | ||
| const doc = parser.parseFromString(sanitized, 'text/html'); | ||
| const table = doc.querySelector('table'); | ||
|
|
||
| if (!table) { |
-
Copy modified lines R48-R49
| @@ -45,7 +45,8 @@ | ||
| "big.js": "6.2.2", | ||
| "exceljs": "4.4.0", | ||
| "file-saver": "2.0.5", | ||
| "@types/file-saver": "2.0.7" | ||
| "@types/file-saver": "2.0.7", | ||
| "dompurify": "^3.3.1" | ||
| }, | ||
| "peerDependencies": { | ||
| "@visactor/vtable": "workspace:*", |
| Package | Version | Security advisories |
| dompurify (npm) | 3.3.1 | None |
…o feat/excel-multiply-sheet-import
[中文版模板 / Chinese template]
🤔 This is a ...
🔗 Related issue link
💡 Background and solution
📝 Changelog
☑️ Self-Check before Merge
🚀 Summary
copilot:summary
🔍 Walkthrough
copilot:walkthrough