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

Remove raw from various template #11803

Merged

Conversation

rioug
Copy link
Collaborator

@rioug rioug commented Nov 13, 2023

What? Why?

Remove raw from various template, as they are introducing security issue. It potentially allows user to insert dangerous code in the html pages.
It looks like a lot of it is left over from Spree, so I don't really have any context as to why they used raw, so I removed it where it didn't make sense to me why it was used. Hopefully I didn't break anything.

Other instance of raw usage that reviewers might want to check:

What should we test?

  • order cycle report email :
    • Create/update supplier name, product name, customer first and last name, with html tag and check they are properly escaped in the order cycle report email.
  • home page alert:
  • Printed invoices:
    • Create/update product name, variant name, supplier name, shipping method name with html tag and check they are properly escaped in the printed invoices
  • Order summary email:
    • Create/update supplier name, variant name_to_display with and check they are properly escaped in the order summary email

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

The title of the pull request will be included in the release notes.

Dependencies

this PR will need to be merge first #11798

@rioug rioug force-pushed the 11801-remove-raw-from-email-template branch 2 times, most recently from f376a51 to 2b2e53b Compare November 13, 2023 05:14
@rioug rioug marked this pull request as ready for review November 13, 2023 05:45
Copy link
Member

@dacook dacook 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 cleaning this up.
I'm not sure but may have spotted a problem.
Also a couple of minor suggestions.

@@ -1,6 +1,6 @@
- if ContentConfig.home_page_alert_html.present?
.alert-cta
%h6= raw ContentConfig.home_page_alert_html
%h6= sanitize(@comment.body, tags: %w(strong em a i span), attributes: %w(href target))
Copy link
Member

Choose a reason for hiding this comment

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

Should @comment.body be ContentConfig.home_page_alert_html ?

Also, if we have a standard set of allowed tags and attributes, I'd suggest defining these in a constant.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed, I must have been tired. Fixed it.

@@ -37,10 +38,11 @@
%tr
%td
#{line_items.first.variant.sku}
- if @distributors_pickup_times.many?
%td
#{line_items.first.product.supplier.name}
Copy link
Member

Choose a reason for hiding this comment

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

I think we can use = instead of interpolation here, and below ;)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nice pick, I cleaned up the file

@rioug rioug requested a review from dacook November 20, 2023 00:53
Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

Great!

But we are still awaiting merge of the dependent PR, so I will move to In Dev until then.

Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

Thank you!

@rioug rioug force-pushed the 11801-remove-raw-from-email-template branch from e8fc1ff to 502df3d Compare December 18, 2023 03:42
@drummer83 drummer83 self-assigned this Dec 19, 2023
@drummer83 drummer83 added the pr-staged-uk staging.openfoodnetwork.org.uk label Dec 19, 2023
@drummer83
Copy link
Contributor

Hi @rioug,
Thanks for this one and the detailed test instructions!

Test cases

I can see the following parts of the app have been modified, so I tried to test them:

  • navigation_helper.rb
    • I added some tags to the locale file and they were displayed as text:
      image
    • Here is the source:
      image
  • Order cycle report email
    • I added some tags to supplier name, hub name, product name, SKU, customer first and last name and they were displayed as text in the shopfront as well as in the order cycle report email:
      image
      image
      image
  • Home page alert
    • I added some tags to the alert content and only the allowed tags from the TrixScrubber were interpreted as HTML - even though not all of them make sense in this context because they are not within the view port anymore, e.g. <h1>. The others were removed (button in this case):
      image
    • Here is the result:
      image
    • Here is the source:
      image
  • Invoices
    • With tags added to supplier name, hub name, product name, SKU, customer first and last name and an adjustment I created all three types of invoices and the tags were all displayed as text. Here is an example (adjustment with tag is not shown here):
      image
  • Order summary email
    • With tags added to supplier name, hub name, product name, SKU, customer first and last name, adjustment and display name (!= display as) I sent the confirmation mail and the tags were all displayed as text:
      image
      image

Questions

  • Is the definition of text_for_button_link still required? Using a simple search I couldn't find any other calls than the one you deleted in this PR.
  • Use TrixScrubber for other super admin created contents as well? These are currently using .html_safe (e.g. ContentConfig.group_signup_detail_html.html_safe). Isn't that a potential risk as well? Like
    • Producer signup pricing table, case studies and detail html
    • Hub signup pricing table, case studies and detail html
    • Group signup pricing table, case studies and detail html

Other findings (out of scope)

  • SKU is only displayed if set on variant level. But it can still be set on product level.
  • Display as is not shown in order confirmation etc.

Conclusion

  • No regressions found. 👍
  • Everything working as expected. 👍
  • Ready for merging! 🚀
  • Would be interesting to hear your thoughts on my questions - thanks! 🙏

Thanks again! Also I have learnt a bit while testing this PR!

@drummer83 drummer83 merged commit 5f7760c into openfoodfoundation:master Dec 22, 2023
52 checks passed
@drummer83 drummer83 removed the pr-staged-uk staging.openfoodnetwork.org.uk label Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

remove usage of raw in Order Cycle Report email template
4 participants