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

[4.0] email cloaking without inline script #19089

Merged
merged 20 commits into from
Apr 1, 2018
Merged

[4.0] email cloaking without inline script #19089

merged 20 commits into from
Apr 1, 2018

Conversation

dgrammatiko
Copy link
Contributor

@dgrammatiko dgrammatiko commented Dec 16, 2017

Pull Request for Issue # .
This PR is part of the series of PRs that try to eliminate the inline scripts from Joomla. (The reason is CSP, please watch @wilsonge 's video from JWC17...)

Summary of Changes

  • We are using custom elements to keep this as simple as possible
  • The B/C break should be minimal (only if devs were using the internals of the plugin or the JHTML lib), I hope this is ok

Testing Instructions

Edit an article and add email: something@somewhere.com
Navigate to the article and check if the email is visible.
Disable javascript and reload the page (email shouldn't be visible)
Go to Admin->plugins->Content - Email Cloaking and change the option Mode then revisit the article, the email shouldn't be a link

Set the editor to codemirror and edit the article popular articles from the sample data.
Replace the contents of the article with:

<p>Test</p>
toto@toto.com

<p>Another</p>
<a href="mailto:toto@toto.com?subject=Mysubject" class="myclass" >email</a>

<p>Another</p>
<a href="http://mce_host/ourdirectory/email@example.org">anytext</a>

<p>Another</p>
<p><a href="mailto:joe@nowhere.com"><span style="font-style: 8pt;">Joe_fontsize8</span></a></p>

<p>Another</p>
<p><a href="mailto:joe@nowhere13.com?subject= A text"><span style="font-size: 14pt;">Joe_subject_ fontsize13</span></a></p>

<p>Another</p>
<p><a href="mailto:joe@nowhere.com"><strong>something</strong></a></p>

<p>Another</p>
<p><a href="mailto:joe@nowhere.com"><strong>mymail@mysite.com</strong></a></p>

<p>Another</p>
<p><a href="mailto:joe@nowhere.com"><strong><span style="font-size: 14px;">mymail@mysite.com</span></strong></a></p>

<p>Another</p>
<p><a href="mailto:joe@nowhere.com"><strong><span style="font-size: 14px;">Joe Nobody</span></strong></a></p>

<p>Another</p>
<p><a href="mailto:joe@nowhere.com?subject= A text"><strong><span style="font-size: 16px;">joe@nowhere.com</span></strong></a></p>

<p>Another</p>
<p><a href="mailto:joe@nowhere.com?subject=Text"><img src="/images/joomla_black.png" alt=""/>joe@nowhere.com</a></p>

<p>Another</p>
<a href="http://mce_host/ourdirectory/email@example.org">email@example.org</a>

<p>Another</p>
<p><a href="mailto:joe@nowhere.com?subject= A text" class="class1 class2"><strong><span style="font-size: 16px;">joe@nowhere.com</span></strong></a></p>

<p>Another</p>
<p><a href="mailto:joe@nowhere13.com?subject= A text" class="class 1 class 2"><span style="font-size: 14pt;">Joe_subject_ fontsize13</span></a></p>

<p>Another</p>
<a href="mailto:toto@toto.com" class="myclass" >toto@toto.com</a>

<p>Another</p>
<a href="mailto:toto@toto.com" class="myclass" >Click Here</a>

<p> More Tests </p>
<p><a href="mailto:demo@demo.com"><span style="color: red;">Contattare l'associazione</span></a></p>
<div class="contact email"> </div>
<p><a href="mailto:demo@demo.com"><strong>Contattare l'associazione</strong></a></p>
<div class="contact email"> </div>
<div class="contact email"> </div>
<div class="contact email"> </div>
<div class="contact email"> ---------------------------------------</div>
<div class="contact email"><a href="mailto:info@testsite.com"><img style="margin: 0px 3px 0px 0px; float: left; width: 21px; height: 21px;" title="A nice title" src="images/powered_by.png" alt="A nice title" width="21" height="21" />info@testsite.com</a></div>
<div class="contact email"> </div>

<div class="contact email"><a href="mailto:info@testsite.com"><img src="images/powered_by.png" alt="" />info@testsite.com</a></div>
<div class="contact email"> </div>
<div><p>texte apres image</p></div>
<div class="contact email"><a href="mailto:info@testsite.com"><img style="margin: 0px 3px 0px 0px; float: left; width: 21px; height: 21px;" title="A nice title" src="images/powered_by.png" alt="A nice title" width="21" height="21" />texte'apresimage</a></div>

<div class="contact email"><a href="mailto:info@testsite.com?subject= A text"><img style="margin: 0px 3px 0px 0px; float: left; width: 21px; height: 21px;" title="A nice title" src="images/powered_by.png" alt="A nice title" width="21" height="21" />texte'apresimage+ sujet</a></div>
<div>
<p>Testing with &lt;span something&gt;some text&lt;/span&gt;</p>
<p><a href="mailto:joe@nowhere.com"><span style="font-size: 18pt;">Joe_fontsize18</span></a></p>
<p><a href="mailto:joe@nowhere13.com?subject= A text"><span style="font-size: 14pt;">Joe'_subject_ fontsize13</span></a></p>
<p>Testing with &lt;span something&gt;email_adress&lt;/span&gt;</p>
<p><a href="mailto:joe@nowhere14.com"><span style="font-style: 14pt;">joe@nowhere14.com</span></a></p>
<p>Testing with (+subject)&lt;span something&gt;email_adress&lt;/span&gt;</p>
<p><a href="mailto:joe@nowhere16.com?subject= A text"><span style="font-size: 16pt;">joe@nowhere16.com</span></a></p>
<p><a href="mailto:joe@nowhere.com"><span style="color: red;">joe@nowhere.com</span></a></p>
<p>Uniquement strong</p>
<p><a href="mailto:joe@nowhere.com"><strong>something</strong></a></p>
<p>Uniquement strong avec subject et mail</p>
<p><a href="mailto:joe@nowhere.com?subject= A text"><strong>joe@nowhere.com</strong></a></p>
<p>strong+spansomething+text</p>
<p><a href="mailto:joe@nobody.com"><strong><span style="font-size: 9px;">Joe' Nobody</span></strong></a></p>
<p>strong+spansomething+mail</p>
<p><a href="mailto:joe@nobody.com"><strong><span style="font-size: 14px;">mymail@mysite.com</span></strong></a></p>
</div>
  

<div> Test plus sign</div>
test@example.com
test+test@example.com
test+@example.com
+test@example.com

Check in the front end that article, with and without javascript enabled!

Expected result

screen shot 2017-12-16 at 15 22 57

All the possible cases as described in the tests:
screen shot 2018-02-07 at 00 03 04

Actual result

Documentation Changes Required

Yes

@C-Lodder
Copy link
Member

Seems good to me. Looking forward to the event listener for Ajax rendered content as I rely on this myself.

@dgrammatiko
Copy link
Contributor Author

@C-Lodder check @Fedik 's comment: #18843 (comment)
I was thinking about something similar

@dgrammatiko
Copy link
Contributor Author

@C-Lodder can you test this one against some ajax created email addresses?
I just moved the code to custom elements so there is no need for an update event, browsers will sort this automatically. There is another thing tho the ajax needs to update the Joomla storage with the new values...

@dgrammatiko
Copy link
Contributor Author

Can someone from the Security Team confirm if simple encoding is ok here or if we need a stronger key-value approach?
Calling @yvesh @SniperSister @mbabker @wilsonge @nibra

@dgrammatiko
Copy link
Contributor Author

Here is what the bots will see:
screen shot 2017-12-16 at 21 34 18

This is after the js has been executed:
screen shot 2017-12-16 at 21 34 32

Good part: ajax inserted content will work without any extra line of code (use the platform for the win)

@C-Lodder
Copy link
Member

Sure, I'll test this tomorrow

@Bakual
Copy link
Contributor

Bakual commented Dec 16, 2017

Just wondering: Does it even make sense to cloak emails? Afaik Google runs JavaScript when they index the sites, so they will index the email addresses as well.
I guess spam bots in 2017 are running JS as well, but that's guessing without having any clue myself 😄
Does anyone know?

@dgrammatiko
Copy link
Contributor Author

@Bakual thats true 😂
But we can still keep it hidden. Since now there is a custom element we can add a click event listener and on click will redirect to the mail app (href=“mailto:a@b.c). This way the dom never gets the actual email printed. And actually that’s the best we can do, but as you said this might already been outdated (you can have a bot with codeception that will beat the above scenario). Anyways people feel secure with such things although all these are security through obscurity, in other words crap

@SniperSister
Copy link
Contributor

Looks good to me

@rdeutz
Copy link
Contributor

rdeutz commented Dec 17, 2017

please fix code style issues

@Fedik
Copy link
Member

Fedik commented Dec 17, 2017

I guess spam bots in 2017 are running JS as well

I think only a complex bots,
there still a lot of old and simple, most of them a dumb, like file_get_contents('http://blabla.com')

@@ -0,0 +1,43 @@
(() => {
class JoomlaHiddenMail extends HTMLElement {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe a bit OCD of me but could we change the class to JoomlaCloakEmail or JoomlaEmailCloak? Apart from being better wording, it ties in more with the PlgContentEmailcloak PHP class

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 @C-Lodder has a good point,
it will be more clear, "where the thing are come from" 😉
JHtmlEmailCloak and JoomlaEmailCloak

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, makes sense, I will change it

newEl.setAttribute('href', 'mailto:' + window.atob(this.getAttribute('first')) + '@' + window.atob(this.getAttribute('last')));

// Get all of the original element attributes, and pass them to the link
for(var i = 0, l = this.attributes.length; i < l; ++i){
Copy link
Member

@C-Lodder C-Lodder Dec 17, 2017

Choose a reason for hiding this comment

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

for (...) { (spacing)

newEl.setAttribute('href', 'mailto:' + window.atob(this.getAttribute('first')) + '@' + window.atob(this.getAttribute('last')));

// Get all of the original element attributes, and pass them to the link
for(var i = 0, l = this.attributes.length; i < l; ++i){
Copy link
Member

Choose a reason for hiding this comment

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

for (...) { (spacing)

@dgrammatiko
Copy link
Contributor Author

@C-Lodder did you manage to try this one?

@C-Lodder
Copy link
Member

Ah crap, will test now

@C-Lodder
Copy link
Member

Tested and seem to work perfectly with content rendered via Ajax

@C-Lodder
Copy link
Member

I have tested this item ✅ successfully on d6f2d72


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/19089.

@rdeutz
Copy link
Contributor

rdeutz commented Dec 31, 2017

please fix the CS issues and don't comment code just remove it

@dgrammatiko
Copy link
Contributor Author

@C-Lodder can you test this with the sample data I put in the description?

@infograf768
Copy link
Member

infograf768 commented Feb 8, 2018

Here are the tests to do:
Test

<p>UTF8 mail<a href="mailto:joomlatest@xn----7sblgc4ag8bhcd.xn--p1ai"> joomlatest@джумла-тест.рф</a></p>

gives
screen shot 2018-02-08 at 09 02 42

Inspector displays address and wrong encoding for utf8
screen shot 2018-02-08 at 09 16 10

And on image

<p><a href="mailto:joomlatest@xn----7sblgc4ag8bhcd.xn--p1ai" rel="alternate"><img src="images/powered_by.png" alt="" /></a></p>

displays nothing
Inspector source
screen shot 2018-02-08 at 09 18 08

and with your example with image above
I also do not get the image
screen shot 2018-02-08 at 09 25 05

Note: I do see the images correctly when editing the article in front or back-end. Therefore it may not be related.
screen shot 2018-02-08 at 09 26 42

@infograf768
Copy link
Member

Correction: I understand these screenshots do not really show source as they are picked from Web Developper Inspector.

In source, the mail adress is obsfucated as should.
So the issues remaining are UTF8 display and Image display

@infograf768
Copy link
Member

infograf768 commented Feb 8, 2018

Concerning the image, I'm afraid it is a Routing issue due to your PR... The article is displayed in a blog menu item.

screen shot 2018-02-08 at 10 10 54

An image not concerned by the email cloak displays OK.

@dgrammatiko
Copy link
Contributor Author

@infograf768 I knew you'll find some bugs here that's the reason I've asked you test! Thanks, will patch things in a bit

@dgrammatiko
Copy link
Contributor Author

@infograf768 now should be ok, both failing cases:
screen shot 2018-02-08 at 13 00 30

@infograf768
Copy link
Member

UTF8 display is corrected but not the path to image when we call it from a blog
screen shot 2018-02-08 at 16 45 36

@infograf768
Copy link
Member

infograf768 commented Feb 8, 2018

Also, when there is a UTF8 subject, it is still garble.

screen shot 2018-02-08 at 16 54 29

@infograf768
Copy link
Member

I have tested this item ✅ successfully on 385af9c

Ok now :)

Question: any way to also add test for utf8 mails ?


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/19089.

@ghost
Copy link

ghost commented Feb 9, 2018

@Fedik or @C-Lodder an you please retest?

@dgrammatiko
Copy link
Contributor Author

Php tests or js tests?

@infograf768
Copy link
Member

Php tests or js tests?

No idea. Something in PlgContentEmailcloakTest.php I guess.

@dgrammatiko
Copy link
Contributor Author

@infograf768 added two more tests for UTF-8, all tests pass now

@Fedik
Copy link
Member

Fedik commented Feb 10, 2018

I have tested this item ✅ successfully on 5ec825e


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/19089.

@ghost
Copy link

ghost commented Feb 10, 2018

@infograf768 can you please retest?

@dgrammatiko
Copy link
Contributor Author

@franz-wohlkoenig he doesn't have to, the last commit was to fix the tests, didn't touch the rest of the code 😏

@ghost
Copy link

ghost commented Feb 10, 2018

Ready to Commit after two successful tests.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Feb 10, 2018
@infograf768
Copy link
Member

@dgt41 Thanks!

@brianteeman brianteeman added this to the Joomla 4.0 milestone Feb 22, 2018
@wilsonge wilsonge merged commit 889d6aa into joomla:4.0-dev Apr 1, 2018
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Apr 1, 2018
@zero-24
Copy link
Contributor

zero-24 commented Apr 1, 2018

@wilsonge why did you merge this with drone / unit tests failing? All Joomla 4 PR's are now failing.

@dgt41 The error looks like to come from this line https://github.com/joomla/joomla-cms/pull/19089/files#diff-a5e4a8ab7a94472482aa9109f381223fR61 as HTMLHelper::_('webcomponent' expects an string and not a array. Here is a PR but please take a look into that too: #20053

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.

None yet