Validate filepath and filename to prevent path traversal (#1604)

Validate filepath and filename to prevent path traversal in modification
command and provide validations for editor plugin.

Co-authored-by: René Pfeuffer <rene.pfeuffer@cloudogu.com>
This commit is contained in:
Eduard Heimbuch
2021-03-25 12:50:24 +01:00
committed by GitHub
parent 08549a37b1
commit d94ebb2e3e
12 changed files with 169 additions and 11 deletions

View File

@@ -136,7 +136,7 @@ describe("test number validation", () => {
});
describe("test path validation", () => {
const invalid = ["//", "some//path", "end//"];
const invalid = ["//", "some//path", "end//", ".", "..", "../"];
for (const path of invalid) {
it(`should return false for '${path}'`, () => {
expect(validator.isPathValid(path)).toBe(false);
@@ -233,3 +233,18 @@ describe("test url validation", () => {
});
}
});
describe("test filename validation", () => {
const invalid = ["", "/", "some/file", ".", "..", "../", "\\", "\\name", "file:some"];
for (const filename of invalid) {
it(`should return false for '${filename}'`, () => {
expect(validator.isFilenameValid(filename)).toBe(false);
});
}
const valid = ["a", "test", "some_file", "end.txt", ".gitignore"];
for (const filename of valid) {
it(`should return true for '${filename}'`, () => {
expect(validator.isFilenameValid(filename)).toBe(true);
});
}
});