Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions util/generate_man.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,15 @@ const doInclude = (content, includes, f) => {
if (!m1.length) return m
/* VitePress MD supports paths relative to base with leading
* '@'. */
if (m1.startsWith('@'))
return doInclude(fs.readFileSync(process.cwd() + '/' + m1.slice(1), 'utf8'), includes, f)
if (m1.startsWith('@')) {
const cwd = process.cwd()
const targetPath = path.resolve(cwd, m1.slice(1))
const relative = path.relative(cwd, targetPath)
if (relative.startsWith('..') || path.isAbsolute(relative)) {
throw new Error("Path traversal detected in include: " + m1)
}
return doInclude(fs.readFileSync(targetPath, 'utf8'), includes, f)
}
const inc_f = path.basename(m1)
for (const fn of includes) {
if (path.basename(fn) == inc_f)
Expand Down