atris 3.72.1 → 3.72.3

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/lib/site.js +10 -2
  2. package/package.json +1 -1
package/lib/site.js CHANGED
@@ -18,13 +18,19 @@ function collectMd(input) {
18
18
  const stat = fs.statSync(input);
19
19
  if (stat.isFile()) return MD_EXTS.has(path.extname(input)) ? [input] : [];
20
20
  const out = [];
21
+ let realRoot; try { realRoot = fs.realpathSync(input); } catch { return out; }
22
+ const inside = (p) => p === realRoot || p.startsWith(realRoot + path.sep);
21
23
  (function walk(dir) {
22
24
  for (const name of fs.readdirSync(dir).sort()) {
23
25
  if (name.startsWith('.')) continue;
24
26
  const full = path.join(dir, name);
25
- let st; try { st = fs.statSync(full); } catch { continue; }
27
+ // lstat, not stat: symlinks are skipped so a site only ever contains files that live in its folder.
28
+ let st; try { st = fs.lstatSync(full); } catch { continue; }
29
+ if (st.isSymbolicLink()) continue;
30
+ let real; try { real = fs.realpathSync(full); } catch { continue; }
31
+ if (!inside(real)) continue;
26
32
  if (st.isDirectory()) { if (!SKIP_DIRS.has(name)) walk(full); }
27
- else if (MD_EXTS.has(path.extname(name))) out.push(full);
33
+ else if (st.isFile() && MD_EXTS.has(path.extname(name))) out.push(full);
28
34
  }
29
35
  })(input);
30
36
  return out;
@@ -103,6 +109,8 @@ function serveSite(dir, port = 4321) {
103
109
  let rel;
104
110
  try { rel = decodeURIComponent((req.url || '/').split('?')[0]); }
105
111
  catch { res.writeHead(400); res.end('bad request'); return; }
112
+ // A null byte makes the fs calls below throw synchronously and crash the server.
113
+ if (rel.includes('\0')) { res.writeHead(400); res.end('bad request'); return; }
106
114
  if (rel.endsWith('/')) rel += 'index.html';
107
115
  const file = path.normalize(path.join(root, rel));
108
116
  // compare against root + separator so a sibling like "site-evil" can't pass for "site"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atris",
3
- "version": "3.72.1",
3
+ "version": "3.72.3",
4
4
  "description": "you say what you want in plain words. atris builds it, checks it, and shows you proof.",
5
5
  "main": "bin/atris.js",
6
6
  "bin": {