Skip to content

Commit

Permalink
Merge pull request #12 from 418sec/2-other-digidocu
Browse files Browse the repository at this point in the history
Security Fix for Stored Cross Site Scripting - huntr.dev
  • Loading branch information
harish81 committed Apr 12, 2021
2 parents a15863d + 6d80885 commit d9f5d42
Show file tree
Hide file tree
Showing 6 changed files with 277 additions and 6 deletions.
18 changes: 18 additions & 0 deletions app/Http/Requests/UpdateProfileRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Rules\CurrentPassword;
use App\User;
use Illuminate\Foundation\Http\FormRequest;
use Stevebauman\Purify\Facades\Purify;

class UpdateProfileRequest extends FormRequest
{
Expand Down Expand Up @@ -44,4 +45,21 @@ public function rules()
}
return [];
}

/**
* Extend the default getValidatorInstance method
* so description field can be escaped
*
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function getValidatorInstance()
{
$request = $this->toArray();
if (array_key_exists('description', $request)) {
$description = $request["description"];
$escaped_description = Purify::clean($description);
$this->merge(array('description' => $escaped_description));
}
return parent::getValidatorInstance();
}
}
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"license": "MIT",
"require": {
"php": "^7.2",
"ext-fileinfo": "*",
"ext-zip": "*",
"barryvdh/laravel-dompdf": "^0.8.5",
"fideloper/proxy": "^4.0",
Expand All @@ -19,10 +20,10 @@
"laravel/tinker": "^1.0",
"laravelcollective/html": "^6.0",
"spatie/laravel-permission": "^3.2",
"stevebauman/purify": "^4.0",
"yajra/laravel-datatables-buttons": "^4.8",
"yajra/laravel-datatables-html": "^4.19",
"yajra/laravel-datatables-oracle": "~9.0",
"ext-fileinfo": "*"
"yajra/laravel-datatables-oracle": "~9.0"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.2",
Expand Down
122 changes: 118 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

135 changes: 135 additions & 0 deletions config/purify.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Settings
|--------------------------------------------------------------------------
|
| The configuration settings array is passed directly to HTMLPurifier.
|
| Feel free to add / remove / customize these attributes as you wish.
|
| Documentation: http://htmlpurifier.org/live/configdoc/plain.html
|
*/

'settings' => [

/*
|--------------------------------------------------------------------------
| Core.Encoding
|--------------------------------------------------------------------------
|
| The encoding to convert input to.
|
| http://htmlpurifier.org/live/configdoc/plain.html#Core.Encoding
|
*/

'Core.Encoding' => 'utf-8',

/*
|--------------------------------------------------------------------------
| Core.SerializerPath
|--------------------------------------------------------------------------
|
| The HTML purifier serializer cache path.
|
| http://htmlpurifier.org/live/configdoc/plain.html#Cache.SerializerPath
|
*/

'Cache.SerializerPath' => storage_path('app/purify'),

/*
|--------------------------------------------------------------------------
| HTML.Doctype
|--------------------------------------------------------------------------
|
| Doctype to use during filtering.
|
| http://htmlpurifier.org/live/configdoc/plain.html#HTML.Doctype
|
*/

'HTML.Doctype' => 'XHTML 1.0 Strict',

/*
|--------------------------------------------------------------------------
| HTML.Allowed
|--------------------------------------------------------------------------
|
| The allowed HTML Elements with their allowed attributes.
|
| http://htmlpurifier.org/live/configdoc/plain.html#HTML.Allowed
|
*/

'HTML.Allowed' => 'h1,h2,h3,h4,h5,h6,b,strong,i,em,a[href|title],ul,ol,li,p[style],br,span,img[width|height|alt|src]',

/*
|--------------------------------------------------------------------------
| HTML.ForbiddenElements
|--------------------------------------------------------------------------
|
| The forbidden HTML elements. Elements that are listed in
| this string will be removed, however their content will remain.
|
| For example if 'p' is inside the string, the string: '<p>Test</p>',
|
| Will be cleaned to: 'Test'
|
| http://htmlpurifier.org/live/configdoc/plain.html#HTML.ForbiddenElements
|
*/

'HTML.ForbiddenElements' => '',

/*
|--------------------------------------------------------------------------
| CSS.AllowedProperties
|--------------------------------------------------------------------------
|
| The Allowed CSS properties.
|
| http://htmlpurifier.org/live/configdoc/plain.html#CSS.AllowedProperties
|
*/

'CSS.AllowedProperties' => 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align',

/*
|--------------------------------------------------------------------------
| AutoFormat.AutoParagraph
|--------------------------------------------------------------------------
|
| The Allowed CSS properties.
|
| This directive turns on auto-paragraphing, where double
| newlines are converted in to paragraphs whenever possible.
|
| http://htmlpurifier.org/live/configdoc/plain.html#AutoFormat.AutoParagraph
|
*/

'AutoFormat.AutoParagraph' => false,

/*
|--------------------------------------------------------------------------
| AutoFormat.RemoveEmpty
|--------------------------------------------------------------------------
|
| When enabled, HTML Purifier will attempt to remove empty
| elements that contribute no semantic information to the document.
|
| http://htmlpurifier.org/live/configdoc/plain.html#AutoFormat.RemoveEmpty
|
*/

'AutoFormat.RemoveEmpty' => false,

],

];
1 change: 1 addition & 0 deletions storage/app/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*
!public/
!.gitignore
!purify/
2 changes: 2 additions & 0 deletions storage/app/purify/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore

0 comments on commit d9f5d42

Please sign in to comment.