secure-file-check 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/cli.js +42 -8
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -42,17 +42,51 @@ function isIgnored(filePath) {
42
42
 
43
43
  async function walkDir(dir) {
44
44
  const results = [];
45
- const list = await fs.readdir(dir, { withFileTypes: true });
45
+ const stack = [dir];
46
+ const seen = new Set();
46
47
 
47
- for (const f of list) {
48
- const fullPath = path.join(dir, f.name);
48
+ while (stack.length) {
49
+ const current = stack.pop();
49
50
 
50
- if (isIgnored(fullPath)) continue;
51
+ let realCurrent;
52
+ try {
53
+ realCurrent = await fs.realpath(current);
54
+ } catch (e) {
55
+ realCurrent = current;
56
+ }
51
57
 
52
- if (f.isDirectory()) {
53
- results.push(...(await walkDir(fullPath)));
54
- } else {
55
- results.push(fullPath);
58
+ if (seen.has(realCurrent)) continue;
59
+ seen.add(realCurrent);
60
+
61
+ let list;
62
+ try {
63
+ list = await fs.readdir(current, { withFileTypes: true });
64
+ } catch (e) {
65
+ // permission denied or not a directory -> skip
66
+ continue;
67
+ }
68
+
69
+ for (const f of list) {
70
+ const fullPath = path.join(current, f.name);
71
+
72
+ if (isIgnored(fullPath)) continue;
73
+
74
+ if (f.isDirectory()) {
75
+ stack.push(fullPath);
76
+ } else if (f.isSymbolicLink()) {
77
+ // resolve symlink target and only traverse directories to avoid cycles
78
+ try {
79
+ const targetReal = await fs.realpath(fullPath);
80
+ const stat = await fs.stat(targetReal);
81
+ if (stat.isDirectory()) stack.push(targetReal);
82
+ else results.push(fullPath);
83
+ } catch (e) {
84
+ // broken symlink or permission issue -> skip
85
+ continue;
86
+ }
87
+ } else {
88
+ results.push(fullPath);
89
+ }
56
90
  }
57
91
  }
58
92
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "secure-file-check",
3
3
  "description": "CLI + API for validating file types and detecting suspicious Office documents (VBA/macro detection).",
4
- "version": "1.0.0",
4
+ "version": "1.0.1",
5
5
  "type": "module",
6
6
  "main": "./src/validator.js",
7
7
  "scripts": {