mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
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:
@@ -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);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user