Skip to content

Commit 5ec7dc3

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 3d17ceb + f3291e5 commit 5ec7dc3

7 files changed

Lines changed: 18 additions & 18 deletions

File tree

src/Http/Controllers/Api/ApiController.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,9 @@
66
use Code16\Sharp\EntityList\SharpEntityList;
77
use Code16\Sharp\Http\Controllers\SharpProtectedController;
88
use Code16\Sharp\Show\SharpShow;
9-
use Code16\Sharp\Utils\Entities\SharpEntityManager;
109

1110
abstract class ApiController extends SharpProtectedController
1211
{
13-
protected SharpEntityManager $entityManager;
14-
15-
public function __construct()
16-
{
17-
parent::__construct();
18-
$this->entityManager = app(SharpEntityManager::class);
19-
}
20-
2112
protected function getListInstance(string $entityKey): SharpEntityList
2213
{
2314
return $this->entityManager->entityFor($entityKey)->getListOrFail();

src/Http/Controllers/Api/ApiFormEditorUploadFormController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
namespace Code16\Sharp\Http\Controllers\Api;
44

55
use Code16\Sharp\Http\Controllers\Api\Requests\EditorUploadFormRequest;
6-
use Illuminate\Routing\Controller;
76

8-
class ApiFormEditorUploadFormController extends Controller
7+
class ApiFormEditorUploadFormController extends ApiController
98
{
109
public function update(string $globalFilter, EditorUploadFormRequest $request, string $entityKey, ?string $instanceId = null)
1110
{

src/Http/Controllers/Api/ApiFormUploadController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
use Code16\Sharp\Utils\FileUtil;
66
use Illuminate\Foundation\Validation\ValidatesRequests;
7-
use Illuminate\Routing\Controller;
87

9-
class ApiFormUploadController extends Controller
8+
class ApiFormUploadController extends ApiController
109
{
1110
use ValidatesRequests;
1211

src/Http/Controllers/Api/ApiFormUploadThumbnailController.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22

33
namespace Code16\Sharp\Http\Controllers\Api;
44

5-
use Code16\Sharp\Auth\SharpAuthorizationManager;
65
use Code16\Sharp\Form\Eloquent\Uploads\Traits\UsesSharpUploadModel;
7-
use Illuminate\Routing\Controller;
86

9-
class ApiFormUploadThumbnailController extends Controller
7+
class ApiFormUploadThumbnailController extends ApiController
108
{
119
use UsesSharpUploadModel;
1210

13-
public function __construct(private readonly SharpAuthorizationManager $authorizationManager) {}
14-
1511
// Used to generate large thumbnail for upload crop modal
1612
public function show(string $globalFilter, string $entityKey, ?string $instanceId = null)
1713
{

tests/Http/Api/ApiFormUploadControllerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Illuminate\Support\Facades\Storage;
55

66
beforeEach(function () {
7+
login();
78
Storage::fake('local');
89
});
910

@@ -102,3 +103,13 @@
102103
->assertStatus(422)
103104
->assertJsonValidationErrorFor('validation_rule.1');
104105
});
106+
107+
it('does not allow to use a path traversal exploit', function () {
108+
$this
109+
->postJson(route('code16.sharp.api.form.upload'), [
110+
'file' => UploadedFile::fake()->create('../../../etc/passwd.txt'),
111+
])
112+
->assertOk();
113+
114+
$this->assertTrue(Storage::disk('local')->exists('tmp/passwd.txt'));
115+
});

tests/Http/Form/FormUploadsTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Support\Facades\Storage;
66

77
beforeEach(function () {
8+
login();
89
Storage::fake('local');
910
});
1011

tests/Unit/Console/GeneratorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
beforeEach(function () {
99
login();
10+
File::deleteDirectory(base_path('app/Sharp'));
11+
});
1012

13+
afterEach(function () {
1114
File::deleteDirectory(base_path('app/Sharp'));
1215
});
1316

0 commit comments

Comments
 (0)