用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/fabioc-aloha/Alex_Skill_Mall --skill error-message-sanitization命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | error-message-sanitization |
| description | Raw error messages leak internal information to users: |
| lastReviewed | 2026-04-30T00:00:00.000Z |
Raw error messages leak internal information to users:
// Bad: leaks internals
catch (err) {
res.status(500).json({ error: err.message, stack: err.stack });
}
Sanitize at system boundaries before returning errors to users.
function sanitizeForUser(error) {
let msg = error.message || 'An error occurred';
// Strip absolute paths
msg = msg.replace(/[A-Z]:\\[^\s]+/gi, '[path]');
msg = msg.replace(/\/(?:home|usr|var|etc)[^\s]+/gi, '[path]');
// Strip stack traces
msg = msg.replace(/\s+at\s+.+\(.+:\d+:\d+\)/g, '');
// Strip connection strings
msg = msg.replace(/(?:mongodb|postgresql|mysql|redis):\/\/[^\s]+/gi, '[connection]');
// Strip Azure resource IDs
msg = msg.replace(/\/subscriptions\/[a-f0-9-]+/gi, '/subscriptions/[id]');
return msg;
}
// Usage
catch (err) {
console.error('Internal error:', err); // Full error for logs
res.status(500).json({
error: sanitizeForUser(err),
requestId: req.id // For support correlation
});
}
const testCases = [
'Failed at C:\\Users\\dev\\project\\src\\api.js:42',
'Connection failed: mongodb://user:pass@host:27017/db',
'/subscriptions/abc-123/resourceGroups/prod/...',
'Error in /home/deploy/app/server.js'
];
testCases.forEach(msg => {
const sanitized = sanitizeForUser({ message: msg });
console.log(sanitized);
// Should not contain actual paths, credentials, or resource IDs
});
security error-handling api privacy