Skip to content

Commit d62bf49

Browse files
Fix CVE-2023-35169 issue in webklex/laravel-imap
1 parent 7b32dde commit d62bf49

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

overrides/webklex/laravel-imap/src/IMAP/Attachment.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ public function save($path = null, $filename = null) {
195195
$path = $path ?: storage_path();
196196
$filename = $filename ?: $this->getName();
197197

198+
// sanitize $name
199+
// order of '..' is important
200+
$filename = str_replace(['\\', '/', chr(0), ':', '..'], '', $filename ?? '');
201+
198202
$path = substr($path, -1) == DIRECTORY_SEPARATOR ? $path : $path.DIRECTORY_SEPARATOR;
199203

200204
return File::put($path.$filename, $this->getContent()) !== false;
@@ -258,6 +262,10 @@ public function setName($name) {
258262
if (preg_match('/%[0-9A-F]{2}/i', $name)) {
259263
$name = urldecode($name);
260264
}
265+
266+
// sanitize $name
267+
// order of '..' is important
268+
$name = str_replace(['\\', '/', chr(0), ':', '..'], '', $name);
261269
}
262270

263271
$this->name = $name;

0 commit comments

Comments
 (0)