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

Adding breadcrumbs to sanitize / serialize. #538

Merged
merged 1 commit into from
Feb 5, 2018
Merged

Adding breadcrumbs to sanitize / serialize. #538

merged 1 commit into from
Feb 5, 2018

Conversation

ryantology
Copy link
Contributor

Breadcrumbs are not being sanitized. When the inputs contain binary data (binary UUID for instance) the json_encode fails and no report is sent.

@Jean85
Copy link
Collaborator

Jean85 commented Feb 2, 2018

Thanks for the contribution!

Have you tried this on a live setup?
Can you please add tests to avoid regressions (and help the porting of this onto the 2.x branch)?

@ryantology
Copy link
Contributor Author

Yes, it has been tested in live setup. Using this fork in production now.

I had some questions when adding this code:

  • Some of the sanitize data has a limit on the depth. Is there a reason for these limits? My breadcrumb arrays are only 3 levels deep but I don't have a ton of test data to know what other breadcrumbs may look like.
  • I will add a test for the data that I have as an example. My use case was that there is binary UUID in sql breadcrumb that fails. Would a test that replicates the context test: https://github.com/getsentry/sentry-php/blob/master/test/Raven/Tests/ClientTest.php#L1255 be adequate for this code?

I didn't see the 2.x version! Will check on that and test this bug against the new branch.

@Jean85
Copy link
Collaborator

Jean85 commented Feb 3, 2018

The 2.x branch is still in development, but we should be near to something usable as an alpha, probably!

As per the data limitation, the reason is that the Sentry server has some hard limits on that, see docs. Breadcrumbs shouldn't have those.

As for the test, yep, that case is good ti imitate.

'data' => array(
'line' => 1216,
'bindings' => array(
array('foo', 'bar'),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be ideal if these tests also tested to see if mb_convert_encoding($value, 'UTF-8'); is working properly. I'm not sure how to include binary data in the test.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe this could help? https://blog-en.openalfa.com/how-to-work-with-binary-data-in-php

Also, temporarely commenting your fix should make the test fail...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The CI tests fail if there are PR comments? Thats kinda cool. I am going to add the binary check in the test and then rebase / squish and remove these comments.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nope, I meant that if you locally comment the piece of code that you applied as a fix, your test has to fail; it's just a practical test to see if your test is properly written and does his job correctly.

@ryantology
Copy link
Contributor Author

Unrelated, but would love to see styleCI added as a CI here to enforce PSR formatting and coding standards. It looks like 2.x dropped the old array() syntax <3

@ryantology
Copy link
Contributor Author

ryantology commented Feb 3, 2018

I think travis is failing because the encoding might be different for some php versions?
https://github.com/getsentry/sentry-php/blob/master/lib/Raven/Serializer.php#L89

My tests locally pass and the new code creates a passing test. Not sure how to proceed. The serializer property on client is protected making it hard to use the build in encoding detection.

@Jean85
Copy link
Collaborator

Jean85 commented Feb 3, 2018

As for CS, 2.x is under PHPCSFixer and it's checked in the Travis build, so we're covered.

For the build failures, it seems that there are some differences for PHP <5.6. Maybe you should try to use some different bytes?

@ryantology
Copy link
Contributor Author

I found a different binary data that seems to work! Pretty random but does work. Squishing commits now.

@Jean85 Jean85 merged commit 0904031 into getsentry:master Feb 5, 2018
Jean85 pushed a commit that referenced this pull request Feb 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants