atris 3.72.2 → 3.72.4
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.
- package/lib/site.js +13 -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
|
-
|
|
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;
|
|
@@ -100,6 +106,11 @@ function serveSite(dir, port = 4321) {
|
|
|
100
106
|
let realRoot = root;
|
|
101
107
|
try { realRoot = fs.realpathSync(root); } catch { /* missing folder: every request 404s */ }
|
|
102
108
|
const server = http.createServer((req, res) => {
|
|
109
|
+
// Only answer requests addressed to this computer, so another website cannot
|
|
110
|
+
// reach the preview by pointing its own name at 127.0.0.1.
|
|
111
|
+
const port = server.address() && server.address().port;
|
|
112
|
+
const host = String(req.headers.host || '').toLowerCase();
|
|
113
|
+
if (![`127.0.0.1:${port}`, `localhost:${port}`, `[::1]:${port}`].includes(host)) { res.writeHead(403); res.end('forbidden'); return; }
|
|
103
114
|
let rel;
|
|
104
115
|
try { rel = decodeURIComponent((req.url || '/').split('?')[0]); }
|
|
105
116
|
catch { res.writeHead(400); res.end('bad request'); return; }
|