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

Handle incorrectly UTF-8 encoded query and cookie url #3371

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

unoduetre
Copy link
Contributor

@unoduetre unoduetre commented Oct 17, 2024

⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

Follow these steps if you are doing a Rails upgrade.

What

Stop sentry alerting on the “invalid byte sequence in UTF-8 errors”.

As discussed with @hannako, we will use a a solution based on an external gem called rack-utf8_sanitizer instead of developing our own gem. This solution will then be used in all our apps by copy-pasting the configuration of this gem.

Why

When security scanning of our site takes place we are inundated with these errors in our slack channel. These errors are not serving any purpose since there is no issue to be solved. Therefore we should remove them to keep all our alerts actionable.

We often get exceptions in Sentry coming from a security checking bot that attempts some attacks by using strings with special characters. All of those "attacks" fail, but they produce exceptions which we would like to ignore, so they do not clutter Sentry. On the other hand we don’t want to ignore exceptions of the same class coming from other sources.

Trello card

@govuk-ci govuk-ci temporarily deployed to government-frontend-pr-3371 October 17, 2024 14:30 Inactive
@unoduetre unoduetre changed the base branch from main to set-show-exceptions-in-tests-to-none October 17, 2024 14:34
Base automatically changed from set-show-exceptions-in-tests-to-none to main October 23, 2024 12:56
Use a different exception when this situation is detected:
* Sanitiser::Strategy::SanitisingError
This error is not sent to Sentry.
See: alphagov/govuk_app_config#402
@unoduetre unoduetre force-pushed the 2938-silently-handle-invalid-byte-sequence-in-utf-8-errors-l branch from 3157aff to 9b5f383 Compare October 23, 2024 13:37
@unoduetre unoduetre marked this pull request as ready for review October 23, 2024 13:43
Copy link
Contributor

@hannako hannako left a comment

Choose a reason for hiding this comment

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

Sorry Mat I'm not really following this code so I've asked a lot of questions!

If you're confident in these settings it might be helpful to split the commits and explain the options you're passing in, with links to documentation.

I'm wondering if some of the complexity you've added is because you're trying to raise a single error type, so you only have to add that single exception in app-config? But looking at https://github.com/alphagov/govuk_app_config/blob/7b8d4536bf8f54a65694d3e17048d77d60355951/lib/govuk_app_config/govuk_error/configuration.rb#L31-L32 I think it's fine to add more than one error type from the same middleware to this file. So keeping the config in the frontend apps simple is maybe more important.

config/application.rb Show resolved Hide resolved
config/application.rb Show resolved Hide resolved
lib/sanitiser/strategy.rb Show resolved Hide resolved
lib/sanitiser/strategy.rb Show resolved Hide resolved
Copy link
Contributor

@hannako hannako left a comment

Choose a reason for hiding this comment

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

Thanks for explaining Mat!

Shall we put this branch on integration and see if we can trigger some of the new errors in our tech channel before we merge alphagov/govuk_app_config#402 ?

@unoduetre
Copy link
Contributor Author

unoduetre commented Oct 24, 2024

Thanks for explaining Mat!

Shall we put this branch on integration and see if we can trigger some of the new errors in our tech channel before we merge alphagov/govuk_app_config#402 ?

I've already tested it on integration. Here is the error produced (which will be ignored after the govuk_app_config PR is merged) for the URL: "https://integration.publishing.service.gov.uk/update-uk-visas-immigration-account-details?%AD":
https://govuk.sentry.io/issues/5998976313/events/bd2880d035fb458aa757a3d63606ec4f/?environment=integration&environment=integration-blue-aws&environment=integration-eks&query=SanitisingError&referrer=previous-event&statsPeriod=90d&stream_index=0

If you want to test more, I can deploy it again.

@hannako
Copy link
Contributor

hannako commented Oct 24, 2024

Thanks for explaining Mat!
Shall we put this branch on integration and see if we can trigger some of the new errors in our tech channel before we merge alphagov/govuk_app_config#402 ?

I've already tested it on integration. Here is the error produced (which will be ignored after the govuk_app_config PR is merged) for the URL: "https://integration.publishing.service.gov.uk/update-uk-visas-immigration-account-details?%AD": https://govuk.sentry.io/issues/5998976313/events/bd2880d035fb458aa757a3d63606ec4f/?environment=integration&environment=integration-blue-aws&environment=integration-eks&query=SanitisingError&referrer=previous-event&statsPeriod=90d&stream_index=0

If you want to test more, I can deploy it again.

Great! No need to test any more feel free to merge tomorrow 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants