Skip to content
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

Implements wrapper method for a more secure unserialize with PHP 7 #13285

Merged
merged 4 commits into from Oct 10, 2018

Conversation

sgiehl
Copy link
Member

@sgiehl sgiehl commented Aug 13, 2018

As this changes will only affect PHP 7 we shouldn't merge this unless we have successful tests running with PHP 7.

I've switched the tests to PHP 7 on this branch, but it would be good to have them continuous to avoid problems in the future

@sgiehl sgiehl added c: Security For issues that make Matomo more secure. Please report issues through HackerOne and not in Github. Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review. labels Aug 13, 2018
@mattab mattab added this to the 3.7.0 milestone Aug 17, 2018
@mattab
Copy link
Member

mattab commented Aug 17, 2018

I've switched the tests to PHP 7 on this branch, but it would be good to have them continuous to avoid problems in the future

as long as we support PHP 5.6 we should still have our Unit+Integration+System tests running 5.6. So maybe you could make the two MySQLI jobs Alltests run php 5.6 ?

@mattab mattab modified the milestones: 3.7.0, 3.6.1 Sep 1, 2018
@tsteur
Copy link
Member

tsteur commented Sep 9, 2018

FYI @mattab we support PHP 5.5.9+ unless I missed something?

@mattab
Copy link
Member

mattab commented Sep 9, 2018

Yes 👍meant 5.5 not 5.6

@sgiehl
Copy link
Member Author

sgiehl commented Sep 10, 2018

The UI tests are currently running on PHP 5.5. All other test suites are using PHP 5.6.
I'd suggest to switch the AllTests to PHP 7, so they are running a bit faster. But we need to adjust some more stuff so all tests have the same results across PHP versions.

@sgiehl sgiehl force-pushed the secureunserialize branch 2 times, most recently from 9f043a0 to f566c47 Compare September 26, 2018 17:57
}

return @unserialize($string);
}
Copy link
Member

Choose a reason for hiding this comment

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

Should unserialize errors be reported in any way? Is it a problem if an exception is thrown here?

Copy link
Member

@diosmosis diosmosis Sep 28, 2018

Choose a reason for hiding this comment

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

I see a lot of uses of @unserialize(), what about allowing callers to specify whether Common::safe_unserialize() should have errors silenced? Think that might be more flexible.

Copy link
Member Author

Choose a reason for hiding this comment

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

@diosmosis you mean something like a third parameter that defines whether to ignore error or not?
Btw. unserialize doesn't throw an exception if the values can't be deserialized. It triggers a E_NOTICE. For PHP 7 it might be fine as it's "catchable" with the Error class. For PHP 5.x that simply results in errors depending on the php configuration.
Do you think it might be suitable to always ignore errors ion PHP 5 and always catch errors on PHP 7, but trigger a Log::debug in that case?

Copy link
Member

Choose a reason for hiding this comment

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

I thought ErrorHandler might turn the notice into an exception, but I can't really remember and haven't tested it... But for this I figured we could let the callers silence Common::safe_unserialize() if they wanted, eg:

$value = @Common::safe_unserialize($value);

I thought about exceptions but noticed some of the uses you changed assume it will only return false on failure, so I guess we can't throw everywhere.

Copy link
Member

Choose a reason for hiding this comment

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

👍 for logging, though

Copy link
Member Author

Choose a reason for hiding this comment

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

added a debug log for that case and also added some tests...

@diosmosis
Copy link
Member

I guess the .travis.yml change needs to be tweaked to whatever is decided upon, otherwise left one comment.

'message' => $e->getMessage(),
'backtrace' => $e->getTraceAsString()
]);
return false;
Copy link
Member

Choose a reason for hiding this comment

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

Can we log the string as well? For a debug log I presume it's ok.

Copy link
Member

Choose a reason for hiding this comment

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

Added this myself, let me know if that's a problem (can remove in new PR if needed).

@diosmosis
Copy link
Member

Left one comment, otherwise looks good to merge.

@diosmosis diosmosis merged commit eb965d4 into 3.x-dev Oct 10, 2018
@diosmosis diosmosis deleted the secureunserialize branch October 10, 2018 23:00
InfinityVoid pushed a commit to InfinityVoid/matomo that referenced this pull request Oct 11, 2018
…atomo-org#13285)

* Implements wrapper method for a more secure unserialize

* run AllTests on PHP 7

* trigger a debug message if unserialize fails on PHP 7 + tests

* Add string to deserialize to debug log.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Security For issues that make Matomo more secure. Please report issues through HackerOne and not in Github. Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants