Skip to content

Commit 382c7b5

Browse files
committed
Enhance path sanitization to normalize and block git directory variations
- Update `apps/editor/src/utils/path-sanitizer.ts` to prevent RCE via git config overrides by making the `.git` segment check in `sanitize_file_name` case-insensitive while stripping trailing dots/spaces, and update `create_safe_path` to strictly reject any `realpath` that contains a `.git` directory. └── apps └── editor └── src ├── commands │ ├── apply-response-command │ │ ├── apply-response-command.ts │ │ ├── response-processor │ │ │ └── handlers │ │ │ └── diff-handler.ts │ │ └── utils │ │ └── file-operations │ │ └── create-file-if-needed.ts │ ├── generate-commit-message-commands │ │ └── actions │ │ └── run-generate-action.ts │ └── history-command │ ├── actions │ │ └── restore-checkpoint.ts │ └── history-command.ts ├── features │ └── checkpoints │ ├── actions │ │ └── create-checkpoint.ts │ └── utils │ ├── copy-optimised-recursively.ts │ └── git-utils.ts └── utils ├── normalize-path.ts └── path-sanitizer.ts
1 parent 1a2a9dd commit 382c7b5

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

‎apps/editor/src/utils/path-sanitizer.ts‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ export const sanitize_file_name = (name: string): string => {
1515
}
1616

1717
const segments = name.split(/[/\\]/)
18-
if (segments.some((seg) => seg === '.git')) {
18+
if (
19+
segments.some((seg) => {
20+
const normalized = seg.replace(/[\s.]+$/, '').toLowerCase()
21+
return normalized == '.git'
22+
})
23+
) {
1924
return ''
2025
}
2126

@@ -39,7 +44,7 @@ export const create_safe_path = (
3944
): string | null => {
4045
const sanitized_name = sanitize_file_name(file_name)
4146
if (!sanitized_name) {
42-
return null // Return null if sanitization results in empty string
47+
return null
4348
}
4449

4550
let resolved_parent: string
@@ -55,6 +60,16 @@ export const create_safe_path = (
5560
while (true) {
5661
try {
5762
const real_path = fs.realpathSync(current_path)
63+
64+
const real_path_segments = real_path.split(/[/\\]/)
65+
if (
66+
real_path_segments.some(
67+
(seg) => seg.replace(/[\s.]+$/, '').toLowerCase() == '.git'
68+
)
69+
) {
70+
return null
71+
}
72+
5873
const prefix = resolved_parent.endsWith(path.sep)
5974
? resolved_parent
6075
: resolved_parent + path.sep

0 commit comments

Comments
 (0)