forked from symfony/symfony
-
Notifications
You must be signed in to change notification settings - Fork 1
[Security] Improve profiler’s panel #1
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
Closed
Closed
Conversation
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
a36c79f
to
b5f34b8
Compare
b5f34b8
to
573e8cb
Compare
573e8cb
to
0c51184
Compare
Opened symfony#57425 |
MatTheCat
pushed a commit
that referenced
this pull request
Aug 13, 2024
…rsimpsons) This PR was merged into the 5.4 branch. Discussion ---------- [Yaml] 🐛 throw ParseException on invalid date | Q | A | ------------- | --- | Branch? | 5.4 <!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Issues | None <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT (found in symfony-tools/docs-builder#179) When parsing the following yaml: ``` date: 6418-75-51 ``` `symfony/yaml` will throw an exception: ``` $ php main.php PHP Fatal error: Uncaught Exception: Failed to parse time string (6418-75-51) at position 6 (5): Unexpected character in /tmp/symfony-yaml/vendor/symfony/yaml/Inline.php:714 Stack trace: #0 /tmp/symfony-yaml/vendor/symfony/yaml/Inline.php(714): DateTimeImmutable->__construct() #1 /tmp/symfony-yaml/vendor/symfony/yaml/Inline.php(312): Symfony\Component\Yaml\Inline::evaluateScalar() #2 /tmp/symfony-yaml/vendor/symfony/yaml/Inline.php(80): Symfony\Component\Yaml\Inline::parseScalar() symfony#3 /tmp/symfony-yaml/vendor/symfony/yaml/Parser.php(790): Symfony\Component\Yaml\Inline::parse() symfony#4 /tmp/symfony-yaml/vendor/symfony/yaml/Parser.php(341): Symfony\Component\Yaml\Parser->parseValue() symfony#5 /tmp/symfony-yaml/vendor/symfony/yaml/Parser.php(86): Symfony\Component\Yaml\Parser->doParse() symfony#6 /tmp/symfony-yaml/vendor/symfony/yaml/Yaml.php(77): Symfony\Component\Yaml\Parser->parse() symfony#7 /tmp/symfony-yaml/main.php(8): Symfony\Component\Yaml\Yaml::parse() symfony#8 {main} thrown in /tmp/symfony-yaml/vendor/symfony/yaml/Inline.php on line 714 ``` This is because the "month" is invalid. Fixing the "month" will trigger about the same issue because the "day" would be invalid. With the current change it will throw a `ParseException`. Commits ------- 6d71a7e 🐛 throw ParseException on invalid date
MatTheCat
pushed a commit
that referenced
this pull request
Oct 1, 2024
…nse from transport (ZhukV) This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [Notifier][TurboSMS] Process partial accepted response from transport | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | None | License | MIT TurboSMS can return `null` as message id, if sms not sent to recipient. Example: ```json { "response_code": 802, "response_status": "SUCCESS_MESSAGE_PARTIAL_ACCEPTED", "response_result": [ { "phone": "recipient_1", "response_code": 406, "message_id": null, "response_status": "NOT_ALLOWED_RECIPIENT_COUNTRY" }, { "phone": "recipient_2", "response_code": 0, "message_id": "f83f8868-5e46-c6cf-e4fb-615e5a293754", "response_status": "OK" } ] } ``` And we receive error: ``` Symfony\Component\Notifier\Message\SentMessage::setMessageId(): Argument #1 ($id) must be of type string, null given, called in /code/vendor/symfony/turbo-sms-notifier/TurboSmsTransport.php on line 93 ``` Symfony use only one phone number for sent, as result we check only first `response_result`. Commits ------- 932dbe3 [Notifier][TurboSMS] Process partial accepted response from transport
MatTheCat
pushed a commit
that referenced
this pull request
Nov 20, 2024
Without the fix running `SYMFONY_PHPUNIT_SKIPPED_TESTS='phpunit.skipped' php ./phpunit src/Symfony/Component/Lock/Tests/Store/DoctrineDbalPostgreSqlStoreTest.php` without the pdo_pgsql extension enabled the generated skip file looked like this: ``` <?php return array ( 'PHPUnit\\Framework\\DataProviderTestSuite' => array ( 'Symfony\\Component\\Lock\\Tests\\Store\\DoctrineDbalPostgreSqlStoreTest::testInvalidDriver' => 1, ), 'Symfony\\Component\\Lock\\Tests\\Store\\DoctrineDbalPostgreSqlStoreTest' => array ( 'testSaveAfterConflict' => 1, 'testWaitAndSaveAfterConflictReleasesLockFromInternalStore' => 1, 'testWaitAndSaveReadAfterConflictReleasesLockFromInternalStore' => 1, 'testSave' => 1, 'testSaveWithDifferentResources' => 1, 'testSaveWithDifferentKeysOnSameResources' => 1, 'testSaveTwice' => 1, 'testDeleteIsolated' => 1, 'testBlockingLocks' => 1, 'testSharedLockReadFirst' => 1, 'testSharedLockWriteFirst' => 1, 'testSharedLockPromote' => 1, 'testSharedLockPromoteAllowed' => 1, 'testSharedLockDemote' => 1, ), ); ``` Thus, running the tests again with the extension enabled would only run 14 tests instead of the expected total number of 16 tests. With the patch applied the generated skip file looks like this: ``` <?php return array ( 'Symfony\\Component\\Lock\\Tests\\Store\\DoctrineDbalPostgreSqlStoreTest' => array ( 'testInvalidDriver with data set #0' => 1, 'testInvalidDriver with data set #1' => 1, 'testSaveAfterConflict' => 1, 'testWaitAndSaveAfterConflictReleasesLockFromInternalStore' => 1, 'testWaitAndSaveReadAfterConflictReleasesLockFromInternalStore' => 1, 'testSave' => 1, 'testSaveWithDifferentResources' => 1, 'testSaveWithDifferentKeysOnSameResources' => 1, 'testSaveTwice' => 1, 'testDeleteIsolated' => 1, 'testBlockingLocks' => 1, 'testSharedLockReadFirst' => 1, 'testSharedLockWriteFirst' => 1, 'testSharedLockPromote' => 1, 'testSharedLockPromoteAllowed' => 1, 'testSharedLockDemote' => 1, ), ); ```
MatTheCat
pushed a commit
that referenced
this pull request
Nov 20, 2024
… providers (xabbuh) This PR was merged into the 5.4 branch. Discussion ---------- [PhpUnitBridge] fix dumping tests to skip with data providers | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | | License | MIT Without the fix running `SYMFONY_PHPUNIT_SKIPPED_TESTS='phpunit.skipped' php ./phpunit src/Symfony/Component/Lock/Tests/Store/DoctrineDbalPostgreSqlStoreTest.php` without the `pdo_pgsql` extension enabled the generated skip file looked like this: ``` <?php return array ( 'PHPUnit\\Framework\\DataProviderTestSuite' => array ( 'Symfony\\Component\\Lock\\Tests\\Store\\DoctrineDbalPostgreSqlStoreTest::testInvalidDriver' => 1, ), 'Symfony\\Component\\Lock\\Tests\\Store\\DoctrineDbalPostgreSqlStoreTest' => array ( 'testSaveAfterConflict' => 1, 'testWaitAndSaveAfterConflictReleasesLockFromInternalStore' => 1, 'testWaitAndSaveReadAfterConflictReleasesLockFromInternalStore' => 1, 'testSave' => 1, 'testSaveWithDifferentResources' => 1, 'testSaveWithDifferentKeysOnSameResources' => 1, 'testSaveTwice' => 1, 'testDeleteIsolated' => 1, 'testBlockingLocks' => 1, 'testSharedLockReadFirst' => 1, 'testSharedLockWriteFirst' => 1, 'testSharedLockPromote' => 1, 'testSharedLockPromoteAllowed' => 1, 'testSharedLockDemote' => 1, ), ); ``` Thus, running the tests again with the extension enabled would only run 14 tests instead of the expected total number of 16 tests. With the patch applied the generated skip file looks like this: ``` <?php return array ( 'Symfony\\Component\\Lock\\Tests\\Store\\DoctrineDbalPostgreSqlStoreTest' => array ( 'testInvalidDriver with data set #0' => 1, 'testInvalidDriver with data set #1' => 1, 'testSaveAfterConflict' => 1, 'testWaitAndSaveAfterConflictReleasesLockFromInternalStore' => 1, 'testWaitAndSaveReadAfterConflictReleasesLockFromInternalStore' => 1, 'testSave' => 1, 'testSaveWithDifferentResources' => 1, 'testSaveWithDifferentKeysOnSameResources' => 1, 'testSaveTwice' => 1, 'testDeleteIsolated' => 1, 'testBlockingLocks' => 1, 'testSharedLockReadFirst' => 1, 'testSharedLockWriteFirst' => 1, 'testSharedLockPromote' => 1, 'testSharedLockPromoteAllowed' => 1, 'testSharedLockDemote' => 1, ), ); ``` Commits ------- 95f41cc fix dumping tests to skip with data providers
MatTheCat
pushed a commit
that referenced
this pull request
Nov 20, 2024
… not throw exception (lyrixx) This PR was merged into the 5.4 branch. Discussion ---------- [HttpKernel] Ensure `HttpCache::getTraceKey()` does not throw exception | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT We have such logs in our logs. It's in our raw PHP logs. They are not caught by monolog, it's too early ``` [11-Oct-2024 01:23:33 UTC] PHP Fatal error: Uncaught Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException: Invalid method override "__CONSTRUCT". in /var/www/redirection.io/backend/blue/vendor/symfony/http-foundation/Request.php:1234 Stack trace: #0 /var/www/redirection.io/backend/blue/vendor/symfony/http-kernel/HttpCache/HttpCache.php(728): Symfony\Component\HttpFoundation\Request->getMethod() #1 /var/www/redirection.io/backend/blue/vendor/symfony/http-kernel/HttpCache/HttpCache.php(207): Symfony\Component\HttpKernel\HttpCache\HttpCache->getTraceKey() #2 /var/www/redirection.io/backend/blue/vendor/symfony/http-kernel/Kernel.php(188): Symfony\Component\HttpKernel\HttpCache\HttpCache->handle() symfony#3 /var/www/redirection.io/backend/blue/web/app.php(9): Symfony\Component\HttpKernel\Kernel->handle() symfony#4 {main} thrown in /var/www/redirection.io/backend/blue/vendor/symfony/http-foundation/Request.php on line 1234 ``` I managed to reproduced locally. * Before the patch, without the http_cache, symfony returns a 405 * After the patch, without the http_cache, symfony returns a 405 * Before the patch, with the http_cache, symfony returns a 500, without any information (too early) * After the patch, with the http_cache, symfony ret 8000 urns a 405 Commits ------- a2ebbe0 [HttpKernel] Ensure HttpCache::getTraceKey() does not throw exception
MatTheCat
pushed a commit
that referenced
this pull request
Dec 16, 2024
…ctor (MaximePinot) This PR was merged into the 6.4 branch. Discussion ---------- [Mime] Fix wrong PHPDoc in `FormDataPart` constructor | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Issues | - <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT I believe the PHPDoc is wrong. As far as I understand, the `FormDataPart` expects instances of `TextPart`: ```php if (!\is_string($item) && !$item instanceof TextPart) { throw new InvalidArgumentException(sprintf('The value of the form field "%s" can only be a string, an array, or an instance of TextPart, "%s" given.', $fieldName, get_debug_type($item))); } ``` https://github.com/symfony/symfony/blob/6.4/src/Symfony/Component/Mime/Part/Multipart/FormDataPart.php#L74 The following code is rejected by PHPStan while it works: ```php final readonly class Foo { public function bar(): void { new FormDataPart([ new TextPart('baz'), ]); } } ``` ```shell ------ ------------------------------------------------------------------------------------------------------------------- Line src/Foo.php ------ ------------------------------------------------------------------------------------------------------------------- 14 Parameter #1 $fields of class Symfony\Component\Mime\Part\Multipart\FormDataPart constructor expects array<array|string|Symfony\Component\Mime\Part\DataPart>, array<int, Symfony\Component\Mime\Part\TextPart> given. ------ ------------------------------------------------------------------------------------------------------------------- ``` (cc `@B`-Galati) Commits ------- 886d4ed [Mime] Fix wrong PHPDoc in `FormDataPart` constructor
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Let’s display the profiler for a request matching a lone lazy firewall:
Since no channel is forced, we know the
ChannelListener
did not run. To make it more obvious, this PR displays(none)
instead of0.00 ms
when the duration is null.Before
After
But what about the
ContextListener
? Since the firewall is stateful we know it ran, yet its displayed duration also is0.00 ms
.Turns out that because the firewall is lazy, the
ContextListener
ran way past the moment theTraceableFirewallListener
stored its data. In fact, it may be theSecurityDataCollector
itself which trigger it by accessing the security token. This PR makes theTraceableFirewallListener
fetch data only when needed, so that they’re up-to-date when theSecurityDataCollector
asks for them.Before
After
Now, let’s add a global access control so that the
AccessListener
can do its job:The profiler then says no security listeners have been recorded 🤔
This is because the
AccessListener
let theExceptionListener
work out a response by throwingAccessDeniedException
s. When this happens, theTraceableFirewallListener
is cut short before it can store the data it needs (note that it also impacts non-lazy firewalls, but past listeners would then be recorded).This PR stores these data before listeners are called, so that they are available even if one of them throws (this includes authenticators’ data which suffer from the same issue).
Before
After
(Other listeners are hidden on this screenshot but they would be displayed in the profiler.)