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

[RTM] Allow to disable input encoding for a whole dca #708

Merged
merged 5 commits into from
Apr 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Resources/contao/classes/DataContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,15 @@ protected function row($strPalette=null)
$this->varValue = \StringUtil::insertTagToSrc($this->varValue);
}

// Use raw request if set globally but allow opting out setting useRawRequestData to false explicitly
$useRawGlobally = isset($GLOBALS['TL_DCA'][$this->strTable]['config']['useRawRequestData']) && $GLOBALS['TL_DCA'][$this->strTable]['config']['useRawRequestData'] === true;
$notRawForField = isset($arrData['eval']['useRawRequestData']) && $arrData['eval']['useRawRequestData'] === false;

if ($useRawGlobally && !$notRawForField)
{
$arrData['eval']['useRawRequestData'] = true;
}

/** @var Widget $objWidget */
$objWidget = new $strClass($strClass::getAttributesFromDca($arrData, $this->strInputName, $this->varValue, $this->strField, $this->strTable, $this));

Expand Down
8 changes: 6 additions & 2 deletions src/Resources/contao/controllers/BackendPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Contao;

use Patchwork\Utf8;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;


Expand Down Expand Up @@ -50,13 +51,16 @@ public function __construct()
*/
public function run()
{
/** @var Request $request */
$request = System::getContainer()->get('request_stack')->getCurrentRequest();

/** @var BackendTemplate|object $objTemplate */
$objTemplate = new \BackendTemplate('be_password');

if (\Input::post('FORM_SUBMIT') == 'tl_password')
{
$pw = \Input::postUnsafeRaw('password');
$cnf = \Input::postUnsafeRaw('confirm');
$pw = $request->request->get('password');
$cnf = $request->request->get('confirm');

// The passwords do not match
if ($pw != $cnf)
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/contao/forms/FormPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ class FormPassword extends \Widget


/**
* Always decode entities
* Always use raw request data.
*
* @param array $arrAttributes An optional attributes array
*/
public function __construct($arrAttributes=null)
{
parent::__construct($arrAttributes);
$this->decodeEntities = true;
$this->useRawRequestData = true;
}


Expand Down
13 changes: 8 additions & 5 deletions src/Resources/contao/library/Contao/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Contao;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategy;


Expand Down Expand Up @@ -320,6 +321,8 @@ public function authenticate()
*/
public function login()
{
/** @var Request $request */
$request = System::getContainer()->get('request_stack')->getCurrentRequest();
Copy link
Member

Choose a reason for hiding this comment

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

This is a behavior change, shouldn't we use getMasterRequest?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's almost always wrong to take the master request. The use cases are only very, very limited. So no: the current request is the way to go.

\System::loadLanguageFile('default');

// Do not continue if username or password are missing
Expand All @@ -339,7 +342,7 @@ public function login()
foreach ($GLOBALS['TL_HOOKS']['importUser'] as $callback)
{
$this->import($callback[0], 'objImport', true);
$blnLoaded = $this->objImport->{$callback[1]}(\Input::post('username', true), \Input::postUnsafeRaw('password'), $this->strTable);
$blnLoaded = $this->objImport->{$callback[1]}(\Input::post('username', true), $request->request->get('password'), $this->strTable);

// Load successfull
if ($blnLoaded === true)
Expand Down Expand Up @@ -399,17 +402,17 @@ public function login()
// The password has been generated with crypt()
if (\Encryption::test($this->password))
{
$blnAuthenticated = \Encryption::verify(\Input::postUnsafeRaw('password'), $this->password);
$blnAuthenticated = \Encryption::verify($request->request->get('password'), $this->password);
}
else
{
list($strPassword, $strSalt) = explode(':', $this->password);
$blnAuthenticated = ($strSalt == '') ? ($strPassword === sha1(\Input::postUnsafeRaw('password'))) : ($strPassword === sha1($strSalt . \Input::postUnsafeRaw('password')));
$blnAuthenticated = ($strSalt == '') ? ($strPassword === sha1($request->request->get('password'))) : ($strPassword === sha1($strSalt . $request->request->get('password')));

// Store a SHA-512 encrpyted version of the password
if ($blnAuthenticated)
{
$this->password = \Encryption::hash(\Input::postUnsafeRaw('password'));
$this->password = \Encryption::hash($request->request->get('password'));
}
}

Expand All @@ -419,7 +422,7 @@ public function login()
foreach ($GLOBALS['TL_HOOKS']['checkCredentials'] as $callback)
{
$this->import($callback[0], 'objAuth', true);
$blnAuthenticated = $this->objAuth->{$callback[1]}(\Input::post('username', true), \Input::postUnsafeRaw('password'), $this);
$blnAuthenticated = $this->objAuth->{$callback[1]}(\Input::post('username', true), $request->request->get('password'), $this);

// Authentication successfull
if ($blnAuthenticated === true)
Expand Down
10 changes: 10 additions & 0 deletions src/Resources/contao/library/Contao/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Doctrine\DBAL\Types\Type;
use Patchwork\Utf8;
use Symfony\Component\HttpFoundation\Request;


/**
Expand Down Expand Up @@ -83,6 +84,7 @@
* @property string $slabel The submit button label
* @property boolean $preserveTags Preserve HTML tags
* @property boolean $decodeEntities Decode HTML entities
* @property boolean useRawRequestData Use the raw request data from the Symfony request
Copy link
Member

Choose a reason for hiding this comment

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

Should we add useRawRequestData to the switch-case on line 345 too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Jop! Added in 31732f9.

* @property integer $minlength The minimum length
* @property integer $maxlength The maximum length
* @property integer $minval The minimum value
Expand Down Expand Up @@ -340,6 +342,7 @@ public function __set($strKey, $varValue)
case 'trailingSlash':
case 'spaceToUnderscore':
case 'doNotTrim':
case 'useRawRequestData':
$this->arrConfiguration[$strKey] = $varValue ? true : false;
break;

Expand Down Expand Up @@ -793,6 +796,13 @@ public function validate()
*/
protected function getPost($strKey)
{
if ($this->useRawRequestData === true)
{
/** @var Request $request */
$request = \System::getContainer()->get('request_stack')->getCurrentRequest();
Copy link
Member

Choose a reason for hiding this comment

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

Same here, I think we should use the master request?

return $request->request->get($strKey);
}

$strMethod = $this->allowHtml ? 'postHtml' : 'post';

if ($this->preserveTags)
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/contao/widgets/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ class Password extends \Widget


/**
* Always decode entities
* Always use raw request data.
*
* @param array $arrAttributes
*/
public function __construct($arrAttributes=null)
{
parent::__construct($arrAttributes);
$this->decodeEntities = true;
$this->useRawRequestData = true;
}


Expand Down