Closed Bug 877260 Opened 13 years ago Closed 13 years ago

Thank-you emails about contributions are HTML-escaped even though they are plaintext

Categories

(addons.mozilla.org Graveyard :: Public Pages, defect)

x86_64
Linux
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
2013-11-12

People

(Reporter: 52qtuqm9, Assigned: robhudson)

Details

(Whiteboard: [good first bug][lang=py][mentor=robhudson])

Attachments

(1 file)

555 bytes, patch
robhudson
: review-
robhudson
: review-
Details | Diff | Splinter Review
Here's the text I've configured for notes thanking people for contributions for my add-on: Thanks so much for supporting the development of the "Send Later 3" add-on. If there's anything I can do to help make it more useful for you, or if you find yourself using a new Thunderbird version to which I haven't yet ported the add-on, please let me know! The thank-you emails that people get have: Content-Type: text/plain; charset="utf-8" And this body: Thanks so much for supporting the development of the "Send Later 3" add-on. If there's anything I can do to help make it more useful for you, or if you find yourself using a new Thunderbird version to which I haven't yet ported the add-on, please let me know! As you can see, the text is being HTML-escaped even though it's not HTML, which cause it to display as garbage in people's inboxes.
Whiteboard: [good first bug][lang=py][mentor=robhudson]
Hi robhudson, I would like to work on this bug. Can you guide me on this? Please tell me about the bug and how to start. Thanks.
Hi I also would like to working on this bug,but it's my first time to work on with debug,can anybody guide me on how to get started with it?Thanks a lot.
Here's where you can get started installing zamboni to develop and test locally: https://zamboni.readthedocs.org/en/latest/ If you get stuck or need help ask questions in #addons on the Mozilla IRC network. The relevant code is in this block: https://github.com/mozilla/zamboni/blob/master/apps/stats/models.py#L261-L320 More specifically, the body of the email is stored in the addons database table which is loaded here as `addon.thankyou_note`: https://github.com/mozilla/zamboni/blob/master/apps/stats/models.py#L305 And used in this template: https://github.com/mozilla/zamboni/blob/master/apps/stats/templates/stats/contribution-thankyou-email.ltxt I don't see a test for this specifically but it seems like it should be here: https://github.com/mozilla/zamboni/blob/master/apps/stats/tests/test_models.py#L95 If it helps this is the commit that added this feature originally: https://github.com/mozilla/zamboni/commit/02bf3f3f21f7c20239ccdd05c0fae1d0baa9b7ea
Sir,I think you can print the value of c and body ,the error may be escape by template.If I was right,you can add safe filter or turn off the autoescape will be ok. :)
Attached patch Patch V1 — — Splinter Review
Attachment #758442 - Flags: review?(robhudson.mozbugs)
The patch looks fine but I'd like to see a unit test to prove it fixes the issue. If you need any help let me know. I would add something here: https://github.com/mozilla/zamboni/blob/master/apps/stats/tests/test_models.py#L95
(In reply to Rob Hudson [:robhudson] from comment #6) ah,I haven't use unit test before but I will try my best. :)
(In reply to Rob Hudson [:robhudson] from comment #6) Should I make my code as git patch and add it as a attachment or make a github pull request after I finished the unit test.Thank you for your help
(In reply to MikeLing from comment #8) > (In reply to Rob Hudson [:robhudson] from comment #6) > Should I make my code as git patch and add it as a attachment or make a > github pull request after I finished the unit test.Thank you for your help Should I add the code in Patch V1 if I make it as a github request?
(In reply to MikeLing from comment #8) > (In reply to Rob Hudson [:robhudson] from comment #6) > Should I make my code as git patch and add it as a attachment or make a > github pull request after I finished the unit test.Thank you for your help Yes, a github pull request is preferred.
(In reply to Rob Hudson [:robhudson] from comment #10) > (In reply to MikeLing from comment #8) Sir,sorry to disturb you.But it's my first time to write in Django.Even thought I had read django-test and unit_testing in Diven in Python,I still don't know how to write the unit test for the app. Can you tell me how to start it?Where can I find the article or tutorial can help me? Or we can see anybody else was interesting about the test writing. Thank you for your help :)
(In reply to MikeLing from comment #11) > (In reply to Rob Hudson [:robhudson] from comment #10) > > (In reply to MikeLing from comment #8) > Sir,sorry to disturb you.But it's my first time to write in Django.Even > thought I had read django-test and unit_testing in Diven in Python,I still > don't know how to write the unit test for the app. Can you tell me how to > start it?Where can I find the article or tutorial can help me? > Or we can see anybody else was interesting about the test writing. > Thank you for your help :) I would look at this test class: https://github.com/mozilla/zamboni/blob/master/apps/stats/tests/test_models.py#L95 Set the db value of the thank you field to something that would not escape properly before your fix, trigger the email, then check the mail that it is escaped properly. That test class should have plenty of examples to look at. If you have any specific questions once you get something almost there I can help get it finished. Thanks.
(In reply to Rob Hudson [:robhudson] from comment #12) You are welcome. It's my pleasure to contribute my effort to mozilla and I also get a lot of help from you. :) I know I was wrong but I need some advises from you.Thank you. --------------------------------------------------------------------------------------- def test_thankyou_note (self): self.addon.enable_thankyou = true // Should I set all the value like self.transaction_id = 1 //transaction_id and enable_thankyou ? self.addon.thankyou_note = u'Thank you for "Send Later 3" add-on.' self.addon.name = u'zamboni' self.addon.save() email = self.mail_thankyou() // Should I fill variables in the function? assert u'Thank you for "Send Later 3" add-on.' in email.body
I tested this with and without your patch and it's good. def test_thankyou_note(self): self.addon.enable_thankyou = True self.addon.thankyou_note = u'Thank you for "Send Later 3" add-on.' self.addon.name = u'Send Later 3' self.addon.save() cont = self.make_contribution('10', 'en-US', amo.CONTRIB_PURCHASE) cont.update(transaction_id='yo', post_data={'payer_email': 'test@tester.com'}) cont.mail_thankyou() eq_(len(mail.outbox), 1) email = mail.outbox[0] eq_(email.to, ['test@tester.com']) assert '&quot;' not in email.body assert u'Thank you for "Send Later 3" add-on.' in email.body There's one potential problem I see however... If a malicious developer gets someone to contribute and receives and email with <script> tags they will not be escaped. However I'm not up on how many mail clients treat text emails with HTML in them and this might be ok?
Is it possible to strip the script tags? I don't think it's a problem with text emails, but we may move to a mix some day.
(In reply to Wil Clouser [:clouserw] from comment #15) > Is it possible to strip the script tags? I don't think it's a problem with > text emails, but we may move to a mix some day. Yes, we have bleach available. Something like: diff --git a/apps/stats/models.py b/apps/stats/models.py index 6f5e7a9..24dfdcd 100644 --- a/apps/stats/models.py +++ b/apps/stats/models.py @@ -5,11 +5,12 @@ from django.db import models from django.template import Context, loader from django.utils import translation -from babel import Locale, numbers +import bleach import caching.base +import tower +from babel import Locale, numbers from jingo import env from jinja2.filters import do_dictsort -import tower from tower import ugettext as _ import amo @@ -302,7 +303,8 @@ class Contribution(amo.models.ModelBase): # Buildup the email components. t = loader.get_template('stats/contribution-thankyou-email.ltxt') c = { - 'thankyou_note': self.addon.thankyou_note, + 'thankyou_note': bleach.clean(unicode(self.addon.thankyou_note), + strip=True), 'addon_name': self.addon.name, 'learn_url': '%s%s?src=emailinfo' % (settings.SITE_URL, '/'.join(url_parts)),
That'd be cool. Either way though, this is fine. If we convert to HTML emails we'll need to be careful to escape things - nothing new there.
Merged: https://github.com/mozilla/zamboni/commit/e4496ea Thanks for your contribution MikeLing!
Assignee: nobody → robhudson.mozbugs
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
Target Milestone: --- → 2013-11-12
Comment on attachment 758442 [details] [diff] [review] Patch V1 Review of attachment 758442 [details] [diff] [review]: ----------------------------------------------------------------- Clearing needinfo? I don't know how this works. Sorry for the spam.
Attachment #758442 - Flags: review?(robhudson.mozbugs)
Attachment #758442 - Flags: review-
Product: addons.mozilla.org → addons.mozilla.org Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: