Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render the error page on invalid media URLs #3202

Merged
merged 1 commit into from May 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Cms/Media.php
Expand Up @@ -48,8 +48,8 @@ public static function link(Model $model = null, string $hash, string $filename)
if (Str::startsWith($hash, $file->mediaToken() . '-') === true) {
return Response::redirect($file->mediaUrl(), 307);
} else {
// don't leak the correct token
return new Response('Not Found', 'text/plain', 404);
// don't leak the correct token, render the error page
return false;
}
}

Expand Down
3 changes: 1 addition & 2 deletions tests/Cms/Media/MediaTest.php
Expand Up @@ -66,8 +66,7 @@ public function testLinkWithInvalidHash()
$file = $this->app->file('projects/test.svg');
$result = Media::link($this->app->page('projects'), 'abcde-12345', $file->filename());

$this->assertInstanceOf(Response::class, $result);
$this->assertEquals(404, $result->code());
$this->assertFalse($result);
}

public function testLinkWithoutModel()
Expand Down
12 changes: 9 additions & 3 deletions tests/Cms/Routes/RouterTest.php
Expand Up @@ -223,7 +223,9 @@ public function testPageMediaRoute()
]
]);

$response = $app->call('media/pages/projects/1234-5678/cover.jpg');
$mediaHash = $app->file('projects/cover.jpg')->mediaHash();

$response = $app->call('media/pages/projects/' . $mediaHash . '/cover.jpg');
$this->assertInstanceOf(Response::class, $response);
}

Expand All @@ -239,7 +241,9 @@ public function testSiteMediaRoute()
]
]);

$response = $app->call('media/site/1234-5678/background.jpg');
$mediaHash = $app->file('background.jpg')->mediaHash();

$response = $app->call('media/site/' . $mediaHash . '/background.jpg');
$this->assertInstanceOf(Response::class, $response);
}

Expand All @@ -259,7 +263,9 @@ public function testUserMediaRoute()
]
]);

$response = $app->call('media/users/test/1234-5678/test.jpg');
$mediaHash = $app->user('test')->file('test.jpg')->mediaHash();

$response = $app->call('media/users/test/' . $mediaHash . '/test.jpg');
$this->assertInstanceOf(Response::class, $response);
}

Expand Down