Skip to content

Commit aad6e74

Browse files
committed
add better include_file glob validation
1 parent 4f397ca commit aad6e74

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/Builder/Concerns/CopiesToBuildDirectory.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,22 @@ private function copyIncludedFiles(): void
121121
));
122122

123123
foreach ($patterns as $pattern) {
124-
$matchingFiles = glob($sourcePath.'/'.$pattern, GLOB_BRACE);
124+
// Skip empty patterns
125+
if (empty($pattern)) {
126+
continue;
127+
}
128+
129+
// Ensure pattern is relative (not absolute) for security
130+
// Prevents /absolute/path on Unix and C:\path on Windows
131+
if (str_starts_with($pattern, '/') || str_contains($pattern, '..') || (PHP_OS_FAMILY === 'Windows' && preg_match('/^[A-Za-z]:/', $pattern))) {
132+
warning("[WARNING] Skipping potentially unsafe include pattern: {$pattern}");
133+
continue;
134+
}
135+
136+
// Normalize the pattern path separators
137+
$pattern = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $pattern);
138+
139+
$matchingFiles = glob($sourcePath.DIRECTORY_SEPARATOR.$pattern, GLOB_BRACE);
125140

126141
foreach ($matchingFiles as $sourceFile) {
127142
$relativePath = substr($sourceFile, strlen($sourcePath) + 1);

0 commit comments

Comments
 (0)