Scan your whole stack
Are you using @lazy-node/windows-unsafe-filename?
Find out what’s in your code.
Scan your apps free in minutes (opens in a new tab)Latest version: v1.0.17
@lazy-node/windows-unsafe-filename was last scanned on 27 Nov 2026 at version 1.0.17. Risk score 0 of 100. No malicious behavior was detected.
| Version | Published | Status |
|---|---|---|
| 1.0.17 LATEST | 27 Nov 2026 | No rules fired |
Findings for v1.0.17. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.
The score describes 1.0.17; other versions have their own rules, not their own score.
The publisher’s own README, as collected from the registry.
這個模組提供了檢測和處理 Windows 系統中不安全檔案名稱的功能。Windows 系統有特定的保留字元和裝置名稱,不能用作檔案名稱。
yarn add @lazy-node/windows-unsafe-filename
yarn-tool add @lazy-node/windows-unsafe-filename
yt add @lazy-node/windows-unsafe-filename
import { hasWindowsUnsafeName, replaceWindowsUnsafeName } from '@lazy-node/windows-unsafe-filename';
// 檢測不安全名稱
const isUnsafe = hasWindowsUnsafeName('con.txt');
console.log(isUnsafe); // 匹配結果陣列
// 替換不安全名稱
const safeName = replaceWindowsUnsafeName('con.txt', 'safe_name');
console.log(safeName); // 'safe_name.txt'
建立 Windows 不安全名稱的正規表示式。
參數:
mode (boolean): 是否使用擴展模式(支援 com00-lpt99)返回值:
RegExp: 檢測 Windows 不安全名稱的正規表示式模式說明:
false (預設): 標準模式,支援 com0-lpt9true: 擴展模式,支援 com00-lpt99檢測字串是否包含 Windows 不安全名稱。
參數:
name (string): 要檢測的字串mode (boolean): 是否使用擴展模式返回值:
RegExpMatchArray | null: 匹配結果,null 表示安全替換 Windows 不安全名稱。
參數:
name (string): 要處理的字串replaceValue (string | function): 替換值或回呼函數mode (boolean): 是否使用擴展模式返回值:
string: 處理後的字串import { hasWindowsUnsafeName } from '@lazy-node/windows-unsafe-filename';
// 檢測常見的 Windows 保留名稱
const testNames = [
'con.txt',
'prn.doc',
'aux.exe',
'nul.bat',
'com1.log',
'lpt1.dat',
'normal.txt'
];
testNames.forEach(name => {
const result = hasWindowsUnsafeName(name);
console.log(`${name}: ${result ? '不安全' : '安全'}`);
});
// 輸出:
// con.txt: 不安全
// prn.doc: 不安全
// aux.exe: 不安全
// nul.bat: 不安全
// com1.log: 不安全
// lpt1.dat: 不安全
// normal.txt: 安全
import { replaceWindowsUnsafeName } from '@lazy-node/windows-unsafe-filename';
// 使用字串替換
const unsafeName = 'con.txt';
const safeName = replaceWindowsUnsafeName(unsafeName, 'safe_name');
console.log(safeName); // 'safe_name.txt'
// 使用回呼函數替換
const unsafeName2 = 'com1.log';
const safeName2 = replaceWindowsUnsafeName(unsafeName2, (match, name, ext) => {
return `device_${name}${ext || ''}`;
});
console.log(safeName2); // 'device_com1.log'
import { hasWindowsUnsafeName, replaceWindowsUnsafeName } from '@lazy-node/windows-unsafe-filename';
// 標準模式(預設)
console.log(hasWindowsUnsafeName('com10.txt')); // null (安全)
console.log(hasWindowsUnsafeName('lpt20.txt')); // null (安全)
// 擴展模式
console.log(hasWindowsUnsafeName('com10.txt', true)); // 匹配結果 (不安全)
console.log(hasWindowsUnsafeName('lpt20.txt', true)); // 匹配結果 (不安全)
// 擴展模式替換
const result = replaceWindowsUnsafeName('com10.txt', 'safe', true);
console.log(result); // 'safe.txt'
import { hasWindowsUnsafeName, replaceWindowsUnsafeName } from '@lazy-node/windows-unsafe-filename';
// 安全的檔案名稱處理
function createSafeFilename(filename: string): string {
if (hasWindowsUnsafeName(filename)) {
return replaceWindowsUnsafeName(filename, (match, name, ext) => {
return `safe_${name}${ext || ''}`;
});
}
return filename;
}
// 批量處理檔案名稱
function processFilenames(filenames: string[]): string[] {
return filenames.map(name => createSafeFilename(name));
}
// 使用範例
const unsafeFilenames = [
'con.txt',
'prn.doc',
'com1.log',
'normal.txt'
];
const safeFilenames = processFilenames(unsafeFilenames);
console.log(safeFilenames);
// ['safe_con.txt', 'safe_prn.doc', 'safe_com1.log', 'normal.txt']
import { sanitizeFilename } from '@lazy-node/sanitize-filename';
import { replaceWindowsUnsafeName } from '@lazy-node/windows-unsafe-filename';
// 綜合檔案名稱安全化
function comprehensiveSanitize(filename: string): string {
// 先處理 Windows 不安全名稱
let safeName = replaceWindowsUnsafeName(filename, 'safe_device');
// 再進行完整的檔案名稱安全化
safeName = sanitizeFilename(safeName, {
trim: true,
replaceToFullWidth: true
});
return safeName;
}
// 使用範例
const unsafeInput = 'con?.txt';
const safeOutput = comprehensiveSanitize(unsafeInput);
console.log(safeOutput); // 'safe_device!.txt'
con - 控制台prn - 印表機aux - 輔助設備nul - 空設備com0 到 com9 - 通訊埠lpt0 到 lpt9 - 並列埠com00 到 com99 - 擴展通訊埠lpt00 到 lpt99 - 擴展並列埠歡迎提交問題和拉取請求!
ISC
Find threats in your stack.
OX Radar can check high-priority threats, like critical package CVEs, against your context.
Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.
The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).
The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.