Repository navigation
Add Psalm taint annotations for session/cookie security #15
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0db8b96
Add Psalm taint annotations for session/cookie security
claude c3d7679
Add tests to achieve 100% code coverage
koriym 7a17a6d
Extract cookie expiration offset constant
koriym 3a66821
Declare provider template types and Override for Psalm 7
koriym File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -7,7 +7,8 @@ | |
| use Attribute; | ||
| use Ray\Di\Di\Qualifier; | ||
|
|
||
| #[Attribute, Qualifier] | ||
| #[Attribute] | ||
| #[Qualifier] | ||
| final class Cookie | ||
| { | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,26 +1,33 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * This file is part of the Ray.AuraSessionModule package. | ||
| * | ||
| * @license http://opensource.org/licenses/MIT MIT | ||
| */ | ||
|
|
||
| namespace Ray\AuraSessionModule; | ||
|
|
||
| use Aura\Session\Session; | ||
| use Aura\Session\SessionFactory; | ||
| use Override; | ||
| use Ray\Di\ProviderInterface; | ||
|
|
||
| /** | ||
| * @deprecated | ||
| * @implements ProviderInterface<Session> | ||
| */ | ||
| class SessionProvider implements ProviderInterface | ||
| { | ||
| /** | ||
| * {@inheritdoc} | ||
| * {@inheritDoc} | ||
| * | ||
| * @SuppressWarnings(PHPMD.Superglobals) | ||
| * @psalm-taint-source input | ||
| */ | ||
| #[Override] | ||
| public function get() | ||
| { | ||
| return (new SessionFactory)->newInstance($_COOKIE); | ||
| return (new SessionFactory())->newInstance($_COOKIE); | ||
| } | ||
| } |
This file contains hidden or 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 Ray\AuraSessionModule; | ||
|
|
||
| use Aura\Session\Session; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| class FakeSessionConsumer | ||
| { | ||
| use AuraSessionInject; | ||
|
|
||
| public function getSession(): Session | ||
| { | ||
| return $this->session; | ||
| } | ||
| } | ||
|
|
||
| class AuraSessionInjectTest extends TestCase | ||
| { | ||
| public function testSetSession(): void | ||
| { | ||
| $session = $this->createMock(Session::class); | ||
| $consumer = new FakeSessionConsumer(); | ||
| $consumer->setSession($session); | ||
|
|
||
| $this->assertSame($session, $consumer->getSession()); | ||
| } | ||
| } |
This file contains hidden or 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,63 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Ray\AuraSessionModule; | ||
|
|
||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| /** @var array<int, array{name: string, value: string, expires: int, path: string, domain: string}> */ | ||
| $setCookieCalls = []; | ||
|
|
||
| /** | ||
| * Override time function for testing | ||
| */ | ||
| function time(): int | ||
| { | ||
| return 1000000; | ||
| } | ||
|
|
||
| /** | ||
| * Override setcookie function for testing | ||
| * | ||
| * @return bool | ||
| */ | ||
| function setcookie(string $name, string $value = '', int $expires = 0, string $path = '', string $domain = '') | ||
| { | ||
| global $setCookieCalls; | ||
|
|
||
| $setCookieCalls[] = [ | ||
| 'name' => $name, | ||
| 'value' => $value, | ||
| 'expires' => $expires, | ||
| 'path' => $path, | ||
| 'domain' => $domain, | ||
| ]; | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| class DeleteCookieInvokerTest extends TestCase | ||
| { | ||
| protected function setUp(): void | ||
| { | ||
| global $setCookieCalls; | ||
|
|
||
| $setCookieCalls = []; | ||
| } | ||
|
|
||
| public function testInvoke(): void | ||
| { | ||
| global $setCookieCalls; | ||
|
|
||
| $invoker = new DeleteCookieInvoker(); | ||
| $invoker('test_cookie', ['path' => '/app', 'domain' => 'example.com']); | ||
|
|
||
| $this->assertCount(1, $setCookieCalls); | ||
| $this->assertSame('test_cookie', $setCookieCalls[0]['name']); | ||
| $this->assertSame('', $setCookieCalls[0]['value']); | ||
| $this->assertSame(1000000 - DeleteCookieInvoker::EXPIRE_OFFSET, $setCookieCalls[0]['expires']); | ||
| $this->assertSame('/app', $setCookieCalls[0]['path']); | ||
| $this->assertSame('example.com', $setCookieCalls[0]['domain']); | ||
| } | ||
| } |
This file contains hidden or 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,18 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Ray\AuraSessionModule; | ||
|
|
||
| use Aura\Session\Session; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| class SessionProviderTest extends TestCase | ||
| { | ||
| public function testGet(): void | ||
| { | ||
| $provider = new SessionProvider(); | ||
| $session = $provider->get(); | ||
| $this->assertInstanceOf(Session::class, $session); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.