Cut over-engineering found by a repo-wide audit
- Config: auth, services, logging, queue and database only repeated the
framework's own files and are gone; the others keep only the keys that
differ (app version, cache serializable_classes, session cookie name,
Markdown mail theme, the shares disk, three Octane values, Livewire's
pagination theme and payload guards).
- Email verification is removed: User never implemented MustVerifyEmail,
so it was never enforced, and SealShare has a single admin and no
registration. CreateNewUser goes with it.
- FileEncryptionService::encryptFile() and generateSalt() were only used
by tests; tests build files with encryptTestFile() in tests/Pest.php.
- The expiration options are defined once, as Share::EXPIRATIONS. "30 Days"
now lasts 30 days instead of a calendar month, and Admin settings only
save a default expiration that is one of the options.
- One-caller helpers are inlined, the uploader reads chunk responses with
XHR's responseType, and starter-kit leftovers are removed.
- Docker: PHP reads the PHP_* limits from the environment itself
(${VAR:-default} in uploads.ini); both entrypoints stop writing the ini.
docker-compose.yml shares the app and scheduler variables through one
anchor. The dev image installs gd for the screenshot publisher and fake
test images.
- Development runs in Docker only: the composer dev script, concurrently,
laravel/pail, laravel/sail, autoprefixer and the shell-quote override
are gone.
- phpunit.xml forces the test environment with <server> entries, so tests
run in the dev container no longer use its real database.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
a62edbcefb
commit
4530298398
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Fortify;
|
||||
|
||||
use App\Concerns\PasswordValidationRules;
|
||||
use App\Concerns\ProfileValidationRules;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Laravel\Fortify\Contracts\CreatesNewUsers;
|
||||
|
||||
class CreateNewUser implements CreatesNewUsers
|
||||
{
|
||||
use PasswordValidationRules, ProfileValidationRules;
|
||||
|
||||
/**
|
||||
* Validate and create a newly registered user.
|
||||
*
|
||||
* @param array<string, string> $input
|
||||
*/
|
||||
public function create(array $input): User
|
||||
{
|
||||
Validator::make($input, [
|
||||
...$this->profileRules(),
|
||||
'password' => $this->passwordRules(),
|
||||
])->validate();
|
||||
|
||||
return User::create([
|
||||
'name' => $input['name'],
|
||||
'email' => $input['email'],
|
||||
'password' => $input['password'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ trait ProfileValidationRules
|
||||
*
|
||||
* @return array<string, array<int, \Illuminate\Contracts\Validation\Rule|array<mixed>|string>>
|
||||
*/
|
||||
protected function profileRules(?int $userId = null): array
|
||||
protected function profileRules(int $userId): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->nameRules(),
|
||||
@@ -35,16 +35,14 @@ trait ProfileValidationRules
|
||||
*
|
||||
* @return array<int, \Illuminate\Contracts\Validation\Rule|array<mixed>|string>
|
||||
*/
|
||||
protected function emailRules(?int $userId = null): array
|
||||
protected function emailRules(int $userId): array
|
||||
{
|
||||
return [
|
||||
'required',
|
||||
'string',
|
||||
'email',
|
||||
'max:255',
|
||||
$userId === null
|
||||
? Rule::unique(User::class)
|
||||
: Rule::unique(User::class)->ignore($userId),
|
||||
Rule::unique(User::class)->ignore($userId),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,10 @@ class DownloadController extends Controller
|
||||
}
|
||||
|
||||
return new StreamedResponse(function () use ($encryptedPath, $key): void {
|
||||
$this->encryptionService->streamDecryptedFile($encryptedPath, $key);
|
||||
foreach ($this->encryptionService->decryptedChunks($encryptedPath, $key) as $chunk) {
|
||||
echo $chunk;
|
||||
flush();
|
||||
}
|
||||
}, 200, $headers);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Livewire\Admin;
|
||||
|
||||
use App\Models\Setting;
|
||||
use App\Models\Share;
|
||||
use App\Services\PasswordGeneratorService;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@@ -92,6 +93,7 @@ class AdminSettings extends Component
|
||||
{
|
||||
$validated = $this->validate([
|
||||
'colorProfile' => ['required', 'string', Rule::in(array_keys(Scheme::profiles()))],
|
||||
'defaultExpiration' => ['nullable', 'string', Rule::in(array_keys(Share::EXPIRATIONS))],
|
||||
'maxFileSize' => ['required', 'integer', 'min:1'],
|
||||
'maxStorageQuota' => ['required', 'integer', 'min:1'],
|
||||
'maxFilesPerShare' => ['required', 'integer', 'min:1'],
|
||||
@@ -101,7 +103,7 @@ class AdminSettings extends Component
|
||||
'siteLogo' => ['nullable', 'file', 'mimes:png,jpg,jpeg,gif,webp', 'max:2048'],
|
||||
...$this->passwordGeneratorRules(),
|
||||
], [
|
||||
...$this->passwordGeneratorMessages(),
|
||||
'passwordCharacterSets.required' => __('Choose at least one kind of character.'),
|
||||
]);
|
||||
|
||||
if ($this->systemPassword) {
|
||||
@@ -160,16 +162,6 @@ class AdminSettings extends Component
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function passwordGeneratorMessages(): array
|
||||
{
|
||||
return [
|
||||
'passwordCharacterSets.required' => __('Choose at least one kind of character.'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the generator settings that passed validation; excluded ones keep their saved value.
|
||||
*
|
||||
|
||||
@@ -6,8 +6,10 @@ use App\Models\Setting;
|
||||
use App\Models\Share;
|
||||
use App\Services\PasswordGeneratorService;
|
||||
use App\Services\ShareService;
|
||||
use Carbon\CarbonInterval;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Attributes\Locked;
|
||||
@@ -135,7 +137,7 @@ class FileUploader extends Component
|
||||
$rules = [];
|
||||
|
||||
if (! Setting::get('allow_never_expire', false)) {
|
||||
$rules['expiration'] = ['required', 'string', 'in:1h,24h,48h,7d,14d,30d'];
|
||||
$rules['expiration'] = ['required', 'string', Rule::in(array_keys(Share::EXPIRATIONS))];
|
||||
}
|
||||
|
||||
if ($this->usePassword) {
|
||||
@@ -158,15 +160,9 @@ class FileUploader extends Component
|
||||
|
||||
$share = $shareService->completeShare($pendingShare, [
|
||||
'password' => $this->usePassword ? $this->password : null,
|
||||
'expires_at' => match ($this->expiration) {
|
||||
'1h' => now()->addHour(),
|
||||
'24h' => now()->addDay(),
|
||||
'48h' => now()->addDays(2),
|
||||
'7d' => now()->addWeek(),
|
||||
'14d' => now()->addDays(14),
|
||||
'30d' => now()->addMonth(),
|
||||
default => null,
|
||||
},
|
||||
'expires_at' => isset(Share::EXPIRATIONS[$this->expiration])
|
||||
? now()->add(CarbonInterval::make(Share::EXPIRATIONS[$this->expiration]['interval']))
|
||||
: null,
|
||||
'max_downloads' => $this->maxDownloads ?: null,
|
||||
]);
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
@@ -45,14 +44,11 @@ class SetupWizard extends Component
|
||||
'name' => $this->name,
|
||||
'email' => $this->email,
|
||||
'password' => Hash::make($this->password),
|
||||
'email_verified_at' => now(),
|
||||
]);
|
||||
|
||||
$user->is_admin = true;
|
||||
$user->save();
|
||||
|
||||
Setting::set('setup_complete', 'true');
|
||||
|
||||
Auth::login($user);
|
||||
|
||||
$this->redirect(route('admin.dashboard'), navigate: true);
|
||||
|
||||
@@ -30,13 +30,7 @@ class ShareDownload extends Component
|
||||
abort(404);
|
||||
}
|
||||
|
||||
if (! $share->isPasswordProtected()) {
|
||||
$this->authenticated = true;
|
||||
}
|
||||
|
||||
if ($share->isPasswordProtected() && session('share_key_'.$share->token)) {
|
||||
$this->authenticated = true;
|
||||
}
|
||||
$this->authenticated = ! $share->isPasswordProtected() || (bool) session('share_key_'.$share->token);
|
||||
}
|
||||
|
||||
public function verifyPassword(ShareService $shareService): void
|
||||
|
||||
@@ -10,6 +10,21 @@ class Share extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The expiration times an uploader can choose, by the id the upload form and Admin settings
|
||||
* store: each one's label and how long a share lasts with it.
|
||||
*
|
||||
* @var array<string, array{label: string, interval: string}>
|
||||
*/
|
||||
public const EXPIRATIONS = [
|
||||
'1h' => ['label' => '1 Hour', 'interval' => '1 hour'],
|
||||
'24h' => ['label' => '24 Hours', 'interval' => '1 day'],
|
||||
'48h' => ['label' => '48 Hours', 'interval' => '2 days'],
|
||||
'7d' => ['label' => '7 Days', 'interval' => '7 days'],
|
||||
'14d' => ['label' => '14 Days', 'interval' => '14 days'],
|
||||
'30d' => ['label' => '30 Days', 'interval' => '30 days'],
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'token',
|
||||
'password',
|
||||
|
||||
@@ -2,12 +2,10 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Fortify\TwoFactorAuthenticatable;
|
||||
|
||||
class User extends Authenticatable
|
||||
@@ -51,16 +49,4 @@ class User extends Authenticatable
|
||||
'is_admin' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user's initials
|
||||
*/
|
||||
public function initials(): string
|
||||
{
|
||||
return Str::of($this->name)
|
||||
->explode(' ')
|
||||
->take(2)
|
||||
->map(fn ($word) => Str::substr($word, 0, 1))
|
||||
->implode('');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,14 +12,6 @@ use NoNameWeb\LivewireMaterial\Support\Scheme;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Actions\Fortify\CreateNewUser;
|
||||
use App\Actions\Fortify\ResetUserPassword;
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -13,14 +12,6 @@ use Laravel\Fortify\Fortify;
|
||||
|
||||
class FortifyServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
@@ -37,7 +28,6 @@ class FortifyServiceProvider extends ServiceProvider
|
||||
private function configureActions(): void
|
||||
{
|
||||
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
|
||||
Fortify::createUsersUsing(CreateNewUser::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,7 +36,6 @@ class FortifyServiceProvider extends ServiceProvider
|
||||
private function configureViews(): void
|
||||
{
|
||||
Fortify::loginView(fn () => view('pages::auth.login'));
|
||||
Fortify::verifyEmailView(fn () => view('pages::auth.verify-email'));
|
||||
Fortify::twoFactorChallengeView(fn () => view('pages::auth.two-factor-challenge'));
|
||||
Fortify::confirmPasswordView(fn () => view('pages::auth.confirm-password'));
|
||||
Fortify::resetPasswordView(fn () => view('pages::auth.reset-password'));
|
||||
|
||||
@@ -53,14 +53,6 @@ class FileEncryptionService
|
||||
return hash_pbkdf2('sha256', $password, hex2bin($salt), self::PBKDF2_ITERATIONS, self::KEY_LENGTH, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a random hex salt (32 bytes = 64 hex chars).
|
||||
*/
|
||||
public function generateSalt(): string
|
||||
{
|
||||
return bin2hex(random_bytes(32));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a random encryption key (32 bytes, returned as hex).
|
||||
*/
|
||||
@@ -207,60 +199,6 @@ class FileEncryptionService
|
||||
return $plaintext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypt a file on the server in the `SEALCHK2` format.
|
||||
*/
|
||||
public function encryptFile(string $sourcePath, string $destPath, string $key, int $chunkSize): void
|
||||
{
|
||||
$source = fopen($sourcePath, 'rb');
|
||||
|
||||
if ($source === false) {
|
||||
throw new RuntimeException("Cannot read source file: {$sourcePath}");
|
||||
}
|
||||
|
||||
$dest = fopen($destPath, 'wb');
|
||||
|
||||
if ($dest === false) {
|
||||
fclose($source);
|
||||
|
||||
throw new RuntimeException("Cannot write encrypted file: {$destPath}");
|
||||
}
|
||||
|
||||
try {
|
||||
$header = $this->createHeader($chunkSize);
|
||||
$noncePrefix = $this->parseHeader($header)['noncePrefix'];
|
||||
$chunkCount = $this->chunkCount((int) filesize($sourcePath), $chunkSize);
|
||||
|
||||
fwrite($dest, $header);
|
||||
|
||||
for ($index = 0; $index < $chunkCount; $index++) {
|
||||
$plaintext = (string) fread($source, $chunkSize);
|
||||
|
||||
fwrite($dest, $this->encryptChunk($plaintext, $key, $noncePrefix, $index, $index === $chunkCount - 1));
|
||||
}
|
||||
} catch (RuntimeException $e) {
|
||||
fclose($source);
|
||||
fclose($dest);
|
||||
@unlink($destPath);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
fclose($source);
|
||||
fclose($dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stream decrypted file content directly to output (echo).
|
||||
*/
|
||||
public function streamDecryptedFile(string $encryptedPath, string $key): void
|
||||
{
|
||||
foreach ($this->decryptedChunks($encryptedPath, $key) as $chunk) {
|
||||
echo $chunk;
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The decrypted content of a file in any of the three formats, chunk by chunk.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user