瀏覽代碼

Be more vigilant in validating file names (#36)

The behavior of `Date.parse` is implementation-dependent and hence
cannot be relied on for security purposes. In particular, the
implementation in Node.js does accept strings such as
`../../../etc/foobar-0` as valid (thanks to the trailing digit).

The failure to properly validate the filename is not exploitable, as
slashes will never be contained in `parts[2]` thanks to the foregoing
`split`, but it is probably still better to have a proper validation in
place.
dev_h
Ingo Blechschmidt 5 年之前
父節點
當前提交
8d71613e6b
No account linked to committer's email address
共有 1 個文件被更改,包括 1 次插入1 次删除
  1. 1
    1
      server/server.js

+ 1
- 1
server/server.js 查看文件

@@ -89,7 +89,7 @@ function handleRequest(request, response) {
89 89
 	} else if (parts[0] === "download") {
90 90
 		var boardName = encodeURIComponent(parts[1]),
91 91
 			history_file = path.join(config.HISTORY_DIR, "board-" + boardName + ".json");
92
-		if (parts.length > 2 && !isNaN(Date.parse(parts[2]))) {
92
+		if (parts.length > 2 && /^[0-9A-Za-z.\-]+$/.test(parts[2])) {
93 93
 			history_file += '.' + parts[2] + '.bak';
94 94
 		}
95 95
 		log("download", { "file": history_file });

Loading…
取消
儲存