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
2 changes: 1 addition & 1 deletion src/core/filestorage/_dto/filestorage.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
@IsString()
@IsNotEmpty()
@ApiProperty({ type: String, default: '/' })
@Matches(/^\/(\.?[^\/\0]+\/?)+$/, { message: 'Path must be a valid path' })
@Matches(/^\/(?:\.?[^\/\0]+\/?)+$/, { message: 'Path must be a valid path' })

Check failure

Code scanning / CodeQL

Inefficient regular expression High

This part of the regular expression may cause exponential backtracking on strings starting with '/' and containing many repetitions of '.'.

Copilot Autofix

AI about 1 year ago

To fix the problem, we need to modify the regular expression to remove the ambiguity that causes exponential backtracking. We can achieve this by making the sub-expression more specific and avoiding nested quantifiers. Specifically, we can replace \.?[^\/\0]+\/? with a more precise pattern that matches valid path segments without ambiguity.

The best way to fix the problem is to use a non-capturing group that matches either a single dot or a sequence of characters that are not slashes or null characters. This will eliminate the nested quantifiers and prevent exponential backtracking.

Suggested changeset 1
src/core/filestorage/_dto/filestorage.dto.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/core/filestorage/_dto/filestorage.dto.ts b/src/core/filestorage/_dto/filestorage.dto.ts
--- a/src/core/filestorage/_dto/filestorage.dto.ts
+++ b/src/core/filestorage/_dto/filestorage.dto.ts
@@ -35,3 +35,3 @@
   @ApiProperty({ type: String, default: '/' })
-  @Matches(/^\/(?:\.?[^\/\0]+\/?)+$/, { message: 'Path must be a valid path' })
+  @Matches(/^\/(?:\.[^\/\0]*|[^\/\0]+\/?)+$/, { message: 'Path must be a valid path' })
   public path: string;
EOF
@@ -35,3 +35,3 @@
@ApiProperty({ type: String, default: '/' })
@Matches(/^\/(?:\.?[^\/\0]+\/?)+$/, { message: 'Path must be a valid path' })
@Matches(/^\/(?:\.[^\/\0]*|[^\/\0]+\/?)+$/, { message: 'Path must be a valid path' })
public path: string;
Copilot is powered by AI and may make mistakes. Always verify output.
public path: string;

@IsOptional()
Expand Down
Loading