(child, parent)
| 39 | * Uses path.relative semantics which CodeQL recognizes as a path-containment |
| 40 | * sanitizer for js/path-injection. */ |
| 41 | function isInside(child, parent) { |
| 42 | if (child === parent) return true; |
| 43 | const rel = path.relative(parent, child); |
| 44 | return rel.length > 0 && !rel.startsWith('..') && !path.isAbsolute(rel); |
| 45 | } |
| 46 | |
| 47 | const server = http.createServer((req, res) => { |
| 48 | /* Parse the request URL defensively. A malformed URL yields 400 before any |