harish81 / digidocu

Open Source Documents Management System Built with Laravel 6
https://nandoliyaharish.gitbook.io/digidocu/
GNU General Public License v3.0
107 stars 64 forks source link

Security Fix for Stored Cross Site Scripting - huntr.dev #12

Closed huntr-helper closed 3 years ago

huntr-helper commented 3 years ago

@thehunckerma (https://huntr.dev/users/thehunckerma) has fixed a potential Stored Cross Site Scripting vulnerability in your repository πŸ”¨. For more information, visit our website (https://huntr.dev/) or click the bounty URL below...

Q | A Version Affected | * Bug Fix | YES Original Pull Request | https://github.com/418sec/digidocu/pull/1

If you are happy with this disclosure, we would love to get a CVE assigned to the vulnerability. Feel free to credit @thehunckerma, the discloser found in the bounty URL (below) and @huntr-helper.

User Comments:

πŸ“Š Metadata *

Bounty URL: https://huntr.dev/bounties/2-other-digidocu/

βš™οΈ Description *

DigiDocu is rendering the description field in the admin's users page without escaping it. A WYSIWYG editor is provided to the users for the profile description which itself has a built-in sanitizer. The user can bypass the WYSIWYG's default sanitizer by intercepting the request (using Burp Suite for instance) and insert some malicious XSS payload. Our fix is to sanitize the HTML before inserting it into the database.

πŸ’» Technical Description *

We are using stevebauman's purify library which is a wrapper around ezyang's htmlpurifier which is a famous standards-compliant HTML filter library. We replace the description input with the sanitized version before inserting it into the database

    // app/Http/Requests/UpdateProfileRequest.php
    /**
     * Extend the default getValidatorInstance method
     * so description field can be escaped
     *
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function getValidatorInstance()
    {
        $request = $this->toArray(); // extract all inputs
        if (array_key_exists('description', $request)) {
            $description = $request["description"]; // get description input
            $escaped_description = Purify::clean($description); // escape the data
            $this->merge(array('description' => $escaped_description)); // replace the old data with the new escaped one
        }
        return parent::getValidatorInstance();
    }

πŸ› Proof of Concept (PoC) *

User test is editing his profile:

image

User test intercepts the request using Burp Suite:

image

User test adds his XSS payload to the description input:

image

Admin super visits test's profile, XSS payload gets executed:

image

πŸ”₯ Proof of Fix (PoF) *

User test is editing his profile:

image

User test intercepts the request using Burp Suite and adds his XSS payload to the description input:

image

Admin super visits test's profile, the <img/> element is rendered but the XSS payload is not executed:

image

The HTML element is sanitized:

image

πŸ‘ User Acceptance Testing (UAT)

There is no unit testing in this project but the feature in question (the WYSIWYG editor) is still working and the HTML is being rendered properly.

esidate commented 3 years ago

Hello @harish81, can you please merge this.

harish81 commented 3 years ago

@thehunckerma Yes of course I will.