Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

allow_extra_attributes does not throw an exception as documented#26534

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ogizanagi merged 1 commit intosymfony:3.4fromdeviantintegral:extra-attributes
Jun 21, 2018

Conversation

@deviantintegral
Copy link
Contributor

@deviantintegraldeviantintegral commentedMar 14, 2018
edited
Loading

QA
Branch?3.4
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed ticketsnone
LicenseMIT
Doc PRnone

The example atDeserializing an object does not actually work. It looks like this is a bug and not a docs issue.#24783 reported the same bug, but it looks like the fix at#24816 isn't complete.

Here's a failing test that copies the existing example.

@ogizanagi
Copy link
Contributor

ogizanagi commentedMar 14, 2018
edited
Loading

Hey@deviantintegral! Thanks for the report.

IIRC, this is not working because there is no metadata.allow_extra_attribute => false cannot work properly without metadata. Hence my fix was only fixing the case where the ObjectNormalizer was instantiated with aClassMetadataFactoryInterface $classMetadataFactory argument.

Right now, I'm not sure if we can do something.

@nicolas-grekasnicolas-grekas added this to the3.4 milestoneMar 15, 2018
@dunglas
Copy link
Member

We may throw if this flag is set but the metadata are not loaded. WDYT?

@ogizanagi
Copy link
Contributor

Could be a solution indeed. Perhaps triggering a deprecation first and throwing on 5.0 if we fear this might break some apps (that would mean the flag wasn't working anyway and they didn't noticed, but an exception at runtime would be worse I think).

@deviantintegral: Would you like to work on this ?

@dunglas
Copy link
Member

I would throw directly. Relying on a non-functional behavior like this one can lead to security vulnerabilities.

@ogizanagi
Copy link
Contributor

But I don't see any security vulnerability here. If the flag is set without metadata factory, noExtraAttributesException is raised but extra attributes will simply be ignored. This exception is only for convenience, no security purpose implied AFAIK.

Anyway, I'm fine with both.

@deviantintegral
Copy link
ContributorAuthor

IIRC, this is not working because there is no metadata. allow_extra_attribute => false cannot work properly without metadata.

I'd expected that something was reflecting the target class, and looking for public properties or set methods. If neither of those existed for a given property in the data being deserialized, then anExtraAttributesException would be thrown. I agree about the convenience factor; my aim was to use it only during early development to ensure that the data being deserialized matched the documentation provided to me.

Is there any reason why we couldn't instantiate a default metadata providing this behaviour, ifallow_extra_attribute => false is set and no factory is provided?

@nicolas-grekas
Copy link
Member

Status: needs work

@deviantintegral
Copy link
ContributorAuthor

I see I need to add the legacy annotations or methods for exception tests. I will do that tomorrow.

One question; if I try to deserialize into a class that only has a private field specified, with no setter, it is not set, but no exception is thrown as it's still in the list of allowed attributes. Is there a decorator class I missed to do field access checks when reflecting the target class?

</person>
EOF;

$encoders =array(newXmlEncoder());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

No need for the xml encoder & serializer for this test. It's just about the object normalizer. See above one.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Good point. I used the full ObjectNormalizer class as I think we need it's implementations to reasonably test this. Should it be copied in as a dummy class or left as is?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is fine with the ObjectNormalizer to me :)

// If additional attributes are not allowed, use a default class metadata factory to check against
// properties and methods.
if (isset($context[static::ALLOW_EXTRA_ATTRIBUTES]) && !$context[static::ALLOW_EXTRA_ATTRIBUTES]) {
$this->classMetadataFactory =newClassMetadataFactory(newAnnotationLoader(newAnnotationReader()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

An issue I see with this might be performances, as there is no cache on contrary of theCacheClassMetadataFactory used on production. If that's only for a convenience exception, it's a free penalty.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We could default to an array cache, or we could leave it to the docs to say "if you are using allow_extra_attributes in production, consider caching the metadata factory". Thoughts?

Copy link
Contributor

@ogizanagiogizanagiMar 23, 2018
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Array cache wouldn't be useful actually.ClassMetadataFactory already has its own in memory cache. So the performances impact might not be really significant in most cases actually.

deviantintegral reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It's why I'm for throwing instead.
Everything else in the component works this way. If someone want to use this feature, it must register properly a metadata factory (and use a cached one as much as possible).

@deviantintegraldeviantintegralforce-pushed theextra-attributes branch 3 times, most recently fromb4c6539 toe70ee3cCompareMarch 23, 2018 19:54
@deviantintegral
Copy link
ContributorAuthor

Can someone rebuild the appveyor build?It threw Failed to decode response: zlib_decode(): data error 69 during composer update.

@ogizanagi
Copy link
Contributor

@deviantintegral : Done.

@nicolas-grekas
Copy link
Member

ping@ogizanagi@dunglas, any decision about throwing or not?

@ogizanagi
Copy link
Contributor

Alright, considering#26534 (comment), let's throw.
I still see no security implications though, so we're able to trigger a deprecation to ensure it doesn't breaks any app thinking they're using the flag properly without metadata factory, but no strong opinion.

The documentation should also benefit from a PR.

dunglas reacted with thumbs up emoji

@dunglas
Copy link
Member

Perfect.

@deviantintegral
Copy link
ContributorAuthor

The appveyor failure is in the Process component, so I'm guessing it's unrelated to this PR. This should be ready for another review.

@fabpot
Copy link
Member

Something went wrong here.@deviantintegral Can you rebase on current 3.4?

@deviantintegral
Copy link
ContributorAuthor

The test failures are fromHttpKernel and are on the 3.4 branch too:

1) Symfony\Component\HttpKernel\Tests\Fragment\InlineFragmentRendererTest::testRenderWithTrustedHeaderDisabledExpectation failed for method name is equal to "handle" when invoked 1 time(s)Parameter 0 for invocation Symfony\Component\HttpKernel\HttpKernelInterface::handle(Symfony\Component\HttpFoundation\Request Object (...), 2, false) does not match expected value.Failed asserting that two objects are equal.--- Expected+++ Actual@@ @@-            'REMOTE_ADDR' => '1.1.1.1'+            'REMOTE_ADDR' => '127.0.0.1'

Copy link
Contributor

@ogizanagiogizanagi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@deviantintegral : Could you also submit a PR to the symfony-docs repository?
Would be great IMHO to add a note block to hint about this.

{
if (!$this->classMetadataFactory) {
if (isset($context[static::ALLOW_EXTRA_ATTRIBUTES]) && !$context[static::ALLOW_EXTRA_ATTRIBUTES]) {
thrownewLogicException('A class metadata factory must be provided in the constructor when setting ALLOW_EXTRA_ATTRIBUTES to false.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Actually should rather use theALLOW_EXTRA_ATTRIBUTE const value here I think.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Where is that constant defined? I don't see that anywhere in the project, at least on the 3.4 and 4.1 branches.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I meanstatic::ALLOW_EXTRA_ATTRIBUTES. the one used in theisset above ^^

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Oh, I get it - the docs and so on don't use the class constant, but the actual lowercase string. I'll update.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

That's why I asked for using the const value. Here you're mentioning the constant in the error message :)

@nicolas-grekas
Copy link
Member

(rebase needed)

@deviantintegraldeviantintegralforce-pushed theextra-attributes branch 2 times, most recently fromd878b4c tob594ad8CompareJune 21, 2018 17:48
deviantintegral added a commit to deviantintegral/symfony-docs that referenced this pull requestJun 21, 2018
@deviantintegral
Copy link
ContributorAuthor

Docs PR filed atsymfony/symfony-docs#9948

Copy link
Contributor

@ogizanagiogizanagi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

if (!$this->classMetadataFactory) {
if (isset($context[static::ALLOW_EXTRA_ATTRIBUTES]) && !$context[static::ALLOW_EXTRA_ATTRIBUTES]) {
thrownewLogicException('A class metadata factory must be provided in the constructor when settingALLOW_EXTRA_ATTRIBUTES to false.');
thrownewLogicException(sprintf('A class metadata factory must be provided in the constructor when setting%s to false.',static::ALLOW_EXTRA_ATTRIBUTES));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Perhaps just wrapping the const value with double quotes

deviantintegral reacted with thumbs up emoji
@ogizanagi
Copy link
Contributor

Thanks@deviantintegral.

@ogizanagiogizanagi merged commita67b650 intosymfony:3.4Jun 21, 2018
ogizanagi added a commit that referenced this pull requestJun 21, 2018
…mented (deviantintegral)This PR was squashed before being merged into the 3.4 branch (closes#26534).Discussion----------allow_extra_attributes does not throw an exception as documented| Q             | A| ------------- | ---| Branch?       | 3.4| Bug fix?      | yes| New feature?  | no| BC breaks?    | no     <!-- seehttps://symfony.com/bc -->| Deprecations? | no| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->| Fixed tickets | none| License       | MIT| Doc PR        | noneThe example at [Deserializing an object](https://symfony.com/doc/current/components/serializer.html#deserializing-an-object) does not actually work. It looks like this is a bug and not a docs issue.#24783 reported the same bug, but it looks like the fix at#24816 isn't complete.Here's a failing test that copies the existing example.Commits-------a67b650 allow_extra_attributes does not throw an exception as documented
This was referencedJun 25, 2018
javiereguiluz pushed a commit to symfony/symfony-docs that referenced this pull requestJul 16, 2018
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull requestJul 16, 2018
…al, javiereguiluz)This PR was submitted for the master branch but it was merged into the 3.4 branch instead (closes#9948).Discussion----------Document the required ClassMetadataFactorySymfony PR atsymfony/symfony#26534Commits-------bc011c0 Rewordb05c1cc Codefence ClassMetadataFactorya4cb67a Document the required ClassMetadataFactory
Guikingone pushed a commit to Guikingone/symfony-docs that referenced this pull requestFeb 12, 2019
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@dunglasdunglasdunglas approved these changes

+1 more reviewer

@ogizanagiogizanagiogizanagi approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.4

Development

Successfully merging this pull request may close these issues.

6 participants

@deviantintegral@ogizanagi@dunglas@nicolas-grekas@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp