Skip to content

Commit f44f7e0

Browse files
committed
fix: validate certificates and their paths
1 parent 93bb22b commit f44f7e0

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

src/PrefillGravityForms/GravityForms/GravityFormsAddon.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,29 @@ private function getCertificateLocation(): string
316316
*/
317317
private function getRootPathToCertificates(): string
318318
{
319-
return (! empty(GravityFormsSettings::make()->get('location-root-path-certificates'))) ? GravityFormsSettings::make()->get('location-root-path-certificates') : storage_path('certificates');
319+
$configured = GravityFormsSettings::make()->get('location-root-path-certificates');
320+
$fallback = storage_path('certificates');
321+
322+
if (empty($configured)) {
323+
return $fallback;
324+
}
325+
326+
$realPath = realpath($configured);
327+
328+
if (false === $realPath) {
329+
return $fallback;
330+
}
331+
332+
$safeBase = realpath(\ABSPATH . '/../../');
333+
334+
if (! str_starts_with($realPath, $safeBase . DIRECTORY_SEPARATOR)) {
335+
return $fallback;
336+
}
337+
338+
if (! is_dir($realPath) || ! is_readable($realPath)) {
339+
return $fallback;
340+
}
341+
342+
return $realPath;
320343
}
321344
}

0 commit comments

Comments
 (0)