Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

[FIX] Stored-XSS application-wide #2

Merged
merged 4 commits into from Oct 12, 2020
Merged

Conversation

alromh87
Copy link

@alromh87 alromh87 commented Sep 24, 2020

Metadata *

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

⚙️ Description *

XSS queries being triggered from people info page by the audit log at the settings, fix sanitizes content before showing to user.

Technical Description *

Even tough Laravel has inbuilt protection for XSS it has been disabled when presenting log: {!! $log['description'] !!} to enable embeding contact links, leading to XSS, htmlentities was used to sanitize data before showing to user, efectively avoiding new as well as already stored XSS.

Edit

Looking further into the code I realized the XSS protection have been disabled in many views so I added a Middleware that will strip html tags using strip_tags, and since strip_tags can be tricked with malformed markup reamaning input is encoded using htmlentities.

Middleware is at app/Http/Middleware/SanitizeInput.php and can be tunned for specific keys adding them to the $except array:

    /**
     * The names of the attributes that should not be trimmed.
     *
     * @var array
     */
    protected $except = [
        'password',
        'password_confirmation',
        '_token',
        ''
    ];

Proof of Concept (PoC) *

  1. Download and setup monica
  2. Create new contact, introducing payload as name:
    < <svg/onload=alert("firstname1")><script> alert("firstname2_xss")</script> <script> alert("midname_xss")</script> <script> alert("Lname_xss")</script><svg/onload=alert(1)> (<svg/onload=alert("nickie1")>)
  3. Go to Settings -> Audit logs
  4. XSS is triggerd

Captura de pantalla de 2020-09-24 11-17-57

Proof of Fix (PoF) *

After fix introduced data is displayed as text and no XSS is executed

Captura de pantalla de 2020-09-24 11-06-30

Stored XSS will be also stripped out and encoded after contact is edited

Captura de pantalla de 2020-09-24 17-53-09

User Acceptance Testing (UAT)

Functionallity is unafected, contact link works as usual
Captura de pantalla de 2020-09-24 11-35-33

@alromh87 alromh87 changed the title [FIX] Stored-XSS using htmlentities() in audit log [FIX] Stored-XSS for all input Sep 24, 2020
@alromh87 alromh87 changed the title [FIX] Stored-XSS for all input [FIX] Stored-XSS application-wide Sep 24, 2020
Add Middleware to clean user input from XSS

Middleware is at app/Http/Middleware/SanitizeInput.php and can be tunned for specific keys adding them to the $except array:
```
    /**
     * The names of the attributes that should not be trimmed.
     *
     * @var array
     */
    protected $except = [
        'password',
        'password_confirmation',
        '_token',
        ''
    ];
```
@ghost ghost requested a review from JamieSlome October 12, 2020 13:58
@JamieSlome JamieSlome merged commit 0764eba into 418sec:master Oct 12, 2020
@huntr-helper
Copy link
Member

Congratulations alromh87 - your fix has been selected! 🎉

Thanks for being part of the community & helping secure the world's open source code.
If you have any questions, please respond in the comments section, or hit us up on Discord. Your bounty is on its way - keep hunting!

Come join us on Discord

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants