Skip to content
Open
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
BAU-27505 Fix Server-Side Request Forgery (SSRF) / Path Traversal issues
  • Loading branch information
Iesan Remus authored and Iesan Remus committed Jun 12, 2025
commit 70bd6f7b4f3971340fbdcffa3f61356703fea4b9
26 changes: 23 additions & 3 deletions example-wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,29 @@ public function stream_seek($offset, $whence) {

private function __getURL($path) {
$this->url = parse_url($path);
if (!isset($this->url['scheme']) || $this->url['scheme'] !== 's3') return $this->url;
if (isset($this->url['user'], $this->url['pass'])) self::setAuth($this->url['user'], $this->url['pass']);
$this->url['path'] = isset($this->url['path']) ? substr($this->url['path'], 1) : '';

// Only allow 's3' scheme
if (!isset($this->url['scheme']) || $this->url['scheme'] !== 's3') {
throw new InvalidArgumentException('Invalid scheme: only s3:// is allowed');
}

// Validate bucket name
if (
!isset($this->url['host']) ||
!preg_match('/^(?!^\d+\.\d+\.\d+\.\d+$)(?!.*\.\.)(?!.*\.$)(?!^\.)[a-z0-9]([a-z0-9.-]{1,61}[a-z0-9])?$/', $this->url['host'])
) {
throw new InvalidArgumentException('Invalid S3 bucket name');
}

// Validate path (no directory traversal)
$this->url['path'] = isset($this->url['path']) ? ltrim($this->url['path'], '/') : '';
if (strpos($this->url['path'], '..') !== false) {
throw new InvalidArgumentException('Invalid S3 object path');
}

if (isset($this->url['user'], $this->url['pass'])) {
self::setAuth($this->url['user'], $this->url['pass']);
}
}

private function __translateMode($mode) {
Expand Down