Skip to content

Commit ca3e200

Browse files
Implement path traversal mitigation in replay.js
Added path traversal mitigation to restrict file access.
1 parent 677d33a commit ca3e200

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

microchess/replay.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,15 @@ function usageAndExit(code = 0) {
153153
else { usageAndExit(1); }
154154
}
155155

156+
const BASE_DIR = path.resolve(__dirname);
156157
const filePath = fileArg ? path.resolve(fileArg) : DEFAULT_OUTPUT;
157158

159+
// Path Traversal Mitigation
160+
if (!filePath.startsWith(BASE_DIR + path.sep)) {
161+
console.error('Access to paths outside the allowed directory is forbidden.');
162+
process.exit(1);
163+
}
164+
158165
// If no args, list last few entries
159166
if (!seedArg && indexArg == null) {
160167
try {

0 commit comments

Comments
 (0)