-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor how session access works * Add csrf token manager and secrets parameter store * Properly add labrador to composer bin * Set php version to 8.2 in CI * temporarily remove static analysis from ci
- Loading branch information
Showing
89 changed files
with
923 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Labrador\DummyApp\Controller; | ||
|
||
use Amp\Http\Server\Request; | ||
use Amp\Http\Server\Response; | ||
use Labrador\Web\Controller\HttpController; | ||
use Labrador\Web\Controller\SelfDescribingController; | ||
use Labrador\Web\RequestAttribute; | ||
use Labrador\Web\Router\GetMapping; | ||
|
||
#[HttpController(new GetMapping('/controller-request-attribute'))] | ||
final class ControllerAttributeController extends SelfDescribingController { | ||
|
||
public function handleRequest(Request $request) : Response { | ||
return new Response(body: $request->getAttribute(RequestAttribute::Controller->value)); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Labrador\Security; | ||
|
||
final class InMemorySecretsSource implements SecretsSource { | ||
|
||
public function __construct( | ||
private readonly string $name, | ||
private readonly array $data | ||
) {} | ||
|
||
public function getName() : string { | ||
return $this->name; | ||
} | ||
|
||
public function getData() : array { | ||
return $this->data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Labrador\Security; | ||
|
||
use Labrador\Web\Exception\InvalidSecretsSource; | ||
|
||
final class JsonFileSecretsSource implements SecretsSource { | ||
|
||
private readonly string $name; | ||
private readonly array $data; | ||
|
||
public function __construct(string $filePath) { | ||
if (!file_exists($filePath)) { | ||
throw InvalidSecretsSource::fromFileNotPresent($filePath); | ||
} | ||
|
||
[$this->name] = explode('.', basename($filePath)); | ||
$this->data = json_decode(file_get_contents($filePath), associative: true, flags: JSON_THROW_ON_ERROR); | ||
} | ||
|
||
public function getName() : string { | ||
return $this->name; | ||
} | ||
|
||
public function getData() : array { | ||
return $this->data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Labrador\Security; | ||
|
||
use Cspray\AnnotatedContainer\Attribute\Service; | ||
use Random\Engine as RandomEngine; | ||
|
||
#[Service] | ||
final class RandomEngineTokenGenerator implements TokenGenerator { | ||
|
||
private readonly RandomEngine $random; | ||
|
||
public function __construct( | ||
RandomEngine $random = null | ||
) { | ||
$this->random = $random ?? new RandomEngine\Secure(); | ||
} | ||
|
||
|
||
public function generateToken() : string { | ||
return bin2hex($this->random->generate()); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Labrador\Security; | ||
|
||
use Adbar\Dot; | ||
use Cspray\AnnotatedContainer\ContainerFactory\ParameterStore; | ||
use Cspray\Typiphy\Type; | ||
use Cspray\Typiphy\TypeIntersect; | ||
use Cspray\Typiphy\TypeUnion; | ||
|
||
final class SecretsParameterStore implements ParameterStore { | ||
|
||
private readonly Dot $data; | ||
|
||
public function __construct(SecretsSource... $secretsSource) { | ||
$data = []; | ||
foreach ($secretsSource as $source) { | ||
$data[$source->getName()] = $source->getData(); | ||
} | ||
$this->data = dot($data); | ||
} | ||
|
||
public function getName() : string { | ||
return 'secrets'; | ||
} | ||
|
||
public function fetch(TypeUnion|Type|TypeIntersect $type, string $key) : mixed { | ||
return $this->data->get($key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Labrador\Security; | ||
|
||
interface SecretsSource { | ||
|
||
public function getName() : string; | ||
|
||
/** | ||
* @return array<non-empty-string, mixed> | ||
*/ | ||
public function getData() : array; | ||
|
||
} |
Oops, something went wrong.
The output of
Random\Engine::generate()
is intended as a low-level building block. It should generally not be used directly, because you don't know what kind of engine is provided and thus you don't know how the output will look. It might be a 16 bit engine that only returns 65536 different values. Even with 64 bit engines the output size is insufficient for anything “token-like”.I recommend to insert the engine into
Random\Randomizer
and then call$randomizer->getBytes($length)
with$length
being at least 16 (i.e. 128 Bits).