? ? ? Pending

User tests: Successful: Unsuccessful:

avatar asika32764
asika32764
28 Mar 2017

Summary of Changes

An idea inspired by Laravel when I'm writing drag and drop installation in #14924

Add CSRF token to head as a meta tag, so we can get the value by Javascript.

Use JHtml::_('form.csrf') to add <meta name="csrf-token" content="14044d42e0488e8362c2ee40f3dcf2d1" /> in <head>

Then we can select this tag to get value:

var token = jQuery('meta[name=csrf-token]').val();

Also we can use X-Csrf-Token: xxx header to validate token.

JHtml_('jquery.token') help us add header to ajaxSetup so we can auto inject token in every $.ajax() calls.

;(function ($) {
	$.ajaxSetup({
		headers: {
			'X-Csrf-Token': $('meta[name="csrf-token"]').attr('content')
		}
	});
})(jQuery);

Testing Instructions

I rewrite sendmail test in configuration to use this pattern, just send a test.

global_configuration_-joomladev-_administration

If we remove JHtml::_('jquery.token') in administrator/components/com_config/view/application/tmpl/default_mail.php, will get fail result.

global_configuration_-joomladev-_administration2

avatar asika32764 asika32764 - open - 28 Mar 2017
avatar asika32764 asika32764 - change - 28 Mar 2017
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 28 Mar 2017
Category Administration com_config Libraries Unit Tests
avatar asika32764 asika32764 - change - 28 Mar 2017
The description was changed
avatar asika32764 asika32764 - edited - 28 Mar 2017
1a8e650 28 Mar 2017 avatar asika32764 CS
avatar asika32764 asika32764 - change - 28 Mar 2017
Labels Added: ? ?
avatar joomla-cms-bot joomla-cms-bot - change - 28 Mar 2017
Category Administration com_config Libraries Unit Tests Administration com_config Templates (admin) Libraries Unit Tests
avatar asika32764 asika32764 - change - 28 Mar 2017
The description was changed
avatar asika32764 asika32764 - edited - 28 Mar 2017
avatar dgt41
dgt41 - comment - 28 Mar 2017
avatar asika32764
asika32764 - comment - 28 Mar 2017

OK, but what class and method should we locate the php code? JHtmlBehavior ???

avatar dgt41
dgt41 - comment - 28 Mar 2017

JHtmlForm::csrf()is fine, you already oded that part

avatar asika32764
asika32764 - comment - 28 Mar 2017

I mean, the core.js is included by JHtmlBehavior::core() but it has no not added CSRF token yet.

Should I call JHtmlForm::csrf() also in JHtmlBehavior::core() or add a new method JHtmlBehavior::token() similar as JHtmlJquery::token() which I wrote in this PR?

avatar dgt41
dgt41 - comment - 28 Mar 2017

Personally I would extend the JHtmlBehavior::core() so everything comes up magically...

avatar asika32764
asika32764 - comment - 28 Mar 2017

OK. I just think there may be someone want to use core.js but do not hope CSRF auto inject to <head>.

But I will follow your comment first if there has no opinion from others.

avatar joomla-cms-bot joomla-cms-bot - change - 28 Mar 2017
Category Administration com_config Libraries Unit Tests Templates (admin) Administration com_config Templates (admin) Libraries JavaScript Unit Tests
avatar asika32764
asika32764 - comment - 28 Mar 2017

Done. Please test with this code in console:

Joomla.request({
  url: '.',
  method: 'POST',
  data: {foo: 'bar'}
});

articles_-joomladev-_administration

I'm wonder that our request method do not support PUT, PATCH and DELETE???

avatar dgt41
dgt41 - comment - 28 Mar 2017

I'm wonder that our request method does not support PUT, PATCH and DELETE???

Maybe forcing this behaviour only to POST is not a great idea...

avatar asika32764
asika32764 - comment - 28 Mar 2017

Maybe forcing this behaviour only to POST is not a great idea...

I think we can leave this issue for J4 since JInput in J3 is not good at handling pure PUT, PATCH and DELETE data.

avatar mbabker
mbabker - comment - 28 Mar 2017

JInput handles them just fine. The magic getter in JInput looks for superglobals or subclasses, and there isn't something matching that definition for any request method except GET and POST.

avatar asika32764
asika32764 - comment - 28 Mar 2017

Maybe I'm miss something but to my knowledge, PUT request data must read by fopen('php://input'), it cannot get from $_PUT. But JInput didn't handle it. (I only see JInputJSON did it)

avatar mbabker
mbabker - comment - 28 Mar 2017

Right, so we already cover that case. GET and POST requests have corresponding superglobals, the other request types don't, and I don't think we should be changing JInput's magic getter to proxy a request method into another object instance personally.

The thing that falls over is if you blindly try to do $input->$method->get() without validating $method (which, sadly, core actually does this). IMO it's not hard to do something like this:


$input = JFactory::getApplication()->input;
$method = $input->getMethod();

if ($method === 'PUT') {
    $data = $input->json->get('foo');
elseif (in_array($method, ['GET', 'POST'])) {
    $data = $input->$method->get('foo');
} else {
    throw new InvalidArgumentException(sprintf('The "%s" request method is not supported by this route, please send a GET, POST, or PUT request.', $method), 405);
}
avatar asika32764
asika32764 - comment - 28 Mar 2017

Actually I think $input->put->get() is a nice pattern since the main subject of JInput is to help us integrate all system INPUT in one interface.

Maybe add a JinputFormdata to parse php://input instead get value from $_REQUEST. This is what I'm working in my framework

But I think it is too big subject for this PR, let's leave this issue for the Framework design, not discussion here.

avatar asika32764
asika32764 - comment - 30 Mar 2017

Here I have a security concern, if we auto inject CSRF into all request, can there be a case that developer or 3rd extensions send a request with CSRF token to outside of Joomla without aware?

avatar asika32764
asika32764 - comment - 1 Apr 2017

Use script option to handle CSRF

avatar franz-wohlkoenig franz-wohlkoenig - change - 1 Apr 2017
Status Pending Discussion
avatar asika32764 asika32764 - change - 27 May 2017
Labels Added: ?
Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 20 Jul 2017
Category Administration com_config Libraries Unit Tests Templates (admin) JavaScript Unit Tests Repository Administration com_admin SQL Postgresql
avatar joomla-cms-bot joomla-cms-bot - change - 20 Jul 2017
Category Administration Unit Tests Repository com_admin SQL Postgresql Administration com_config Templates (admin) Libraries JavaScript Unit Tests
avatar zero-24 zero-24 - change - 29 Jul 2017
Status Discussion Pending
Labels
avatar zero-24 zero-24 - test_item - 29 Jul 2017 - Tested successfully
avatar zero-24
zero-24 - comment - 29 Jul 2017

I have tested this item successfully on f9e0372

After installing a new site based on that branch here the send mail button still works. Thanks


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

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 29 Jul 2017

@zero-24 can this be local tested (mamp) using Mailer "Sendmail"?

avatar zero-24
zero-24 - comment - 29 Jul 2017

I don't know about mamp but in xampp there is a folder where all mails get saved. Just check how it works before the patch. As it should work like the same after the patch

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 29 Jul 2017

Without Patch using Default-Path "/usr/sbin/sendmail" get after Click on Button "Send Test Mail" Error Test mail could not be send and Notice Could not execute: /usr/sbin/sendmail.

If i get same Result using PR is this a successfully Test?

avatar zero-24
zero-24 - comment - 29 Jul 2017

hmm IMO it would better to do a working test.

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 29 Jul 2017

thanks, hopefully another one will test.

avatar asika32764
asika32764 - comment - 29 Jul 2017

If you are using MAMP in MacOS, I guess select the PHP Mail option may work.

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 29 Jul 2017

@asika32764 none of the 3 works, this is from "PHP Mail":
bildschirmfoto 2017-07-29 um 13 47 55

avatar asika32764 asika32764 - change - 29 Jul 2017
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2017-07-29 15:57:36
Closed_By asika32764
Labels
avatar asika32764 asika32764 - close - 29 Jul 2017
avatar zero-24
zero-24 - comment - 29 Jul 2017

@asika32764 Isn't the above error coming from the local envoirment? As this should have nothing todo with the patch here?

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 29 Jul 2017

i haven't applied the PR, so this Notice and Errors don't come from PR.

avatar asika32764 asika32764 - change - 29 Jul 2017
Status Closed New
Closed_Date 2017-07-29 15:57:36
Closed_By asika32764
avatar asika32764 asika32764 - change - 29 Jul 2017
Status New Pending
avatar asika32764 asika32764 - reopen - 29 Jul 2017
avatar asika32764
asika32764 - comment - 29 Jul 2017

A mistake that deleted the branch from forked repo, just restored it.

avatar asika32764
asika32764 - comment - 29 Jul 2017

@franz-wohlkoenig Actually I think it is successfully test if it return same message before and after patch.

avatar franz-wohlkoenig franz-wohlkoenig - test_item - 29 Jul 2017 - Tested successfully
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 29 Jul 2017

I have tested this item successfully on f9e0372

Got same Messages with PR as without.


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

avatar franz-wohlkoenig franz-wohlkoenig - change - 29 Jul 2017
Status Pending Ready to Commit
Easy No Yes
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 29 Jul 2017

RTC after two successful tests.

avatar mbabker mbabker - close - 29 Jul 2017
avatar mbabker mbabker - merge - 29 Jul 2017
avatar mbabker mbabker - change - 29 Jul 2017
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2017-07-29 16:57:50
Closed_By mbabker
Labels Added: ?
avatar pawan0446
pawan0446 - comment - 12 Nov 2018

I have not tested this item.


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

avatar pawan0446
pawan0446 - comment - 12 Nov 2018

I have not tested this item.


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

avatar pawan0446 pawan0446 - test_item - 12 Nov 2018 - Not tested

Add a Comment

Login with GitHub to post a comment