🐛 修复本地存储文件删除失败的问题
问题:sanitizeInput 函数将 / 转义为 /,导致文件路径错误 修复:从 XSS 过滤中移除对 / 的转义,因为它是路径分隔符的合法字符 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -162,19 +162,19 @@ app.use((req, res, next) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// XSS过滤中间件(用于用户输入)- 增强版
|
// XSS过滤中间件(用于用户输入)- 增强版
|
||||||
|
// 注意:不转义 / 因为它是文件路径的合法字符
|
||||||
function sanitizeInput(str) {
|
function sanitizeInput(str) {
|
||||||
if (typeof str !== 'string') return str;
|
if (typeof str !== 'string') return str;
|
||||||
|
|
||||||
// 1. 基础HTML实体转义
|
// 1. 基础HTML实体转义(不包括 / 因为是路径分隔符)
|
||||||
let sanitized = str
|
let sanitized = str
|
||||||
.replace(/[&<>"'\/`]/g, (char) => {
|
.replace(/[&<>"'`]/g, (char) => {
|
||||||
const map = {
|
const map = {
|
||||||
'&': '&',
|
'&': '&',
|
||||||
'<': '<',
|
'<': '<',
|
||||||
'>': '>',
|
'>': '>',
|
||||||
'"': '"',
|
'"': '"',
|
||||||
"'": ''',
|
"'": ''',
|
||||||
'/': '/',
|
|
||||||
'`': '`'
|
'`': '`'
|
||||||
};
|
};
|
||||||
return map[char];
|
return map[char];
|
||||||
|
|||||||
Reference in New Issue
Block a user