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

🐛 [Bug]: Django (pongo2) integration vulnerability to XSS #281

Closed
3 tasks done
bastianwegge opened this issue Aug 9, 2023 · 10 comments · Fixed by #326
Closed
3 tasks done

🐛 [Bug]: Django (pongo2) integration vulnerability to XSS #281

bastianwegge opened this issue Aug 9, 2023 · 10 comments · Fixed by #326
Assignees
Labels
☢️ Bug Something isn't working

Comments

@bastianwegge
Copy link

Bug Description

Currently inside of pongo2 there's a setting that sets pongo2.SetAutoescape(false) which disables HTML sanitization, as far as I can see. This makes the gofiber/template/django integration unusable for my project.

How to Reproduce

Steps to reproduce the behavior:

  1. Create a basic project including gofiber + gofiber/template/django
  2. Create a variable with a string <script>alert("ALERTAAAA");</script>
  3. Print the variable into a template
  4. You have a potential XSS attack if the variable was created by user-input

Expected Behavior

I'd expect HTML sanitization to be active at all times. I'd also expect some documentation on how to explicitly deactivate sanitization for a non-user-input variable that is able to render valid HTML.

Template package Version

Django - v3.1.5

Code Snippet (optional)

No response

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my problem prior to opening this one.
  • I understand that improperly formatted bug reports may be closed without explanation.
@bastianwegge bastianwegge added the ☢️ Bug Something isn't working label Aug 9, 2023
@gaby
Copy link
Member

gaby commented Jan 8, 2024

We could add a config value for this, would that work for you @bastianwegge ?

@sixcolors
Copy link
Member

sixcolors commented Jan 8, 2024

@gaby shouldn't we set it to true?

pongo2.SetAutoescape(false)

@gofiber/maintainers This seems like a security vulnerability to me.

@gaby
Copy link
Member

gaby commented Jan 8, 2024

@sixcolors I'd say yes. Is there a use case for having this disable?

@sixcolors
Copy link
Member

@sixcolors I'd say yes. Is there a use case for having this disable?

Not sure. I’ll have to read pnogo2 docs. There are valid reasons to allow unsafe. But I don’t know why you would do it globally. Unless it doesn’t have a way to do it selectively.

@gaby
Copy link
Member

gaby commented Jan 8, 2024

@sixcolors It only works per template or globally. flosch/pongo2#312

We can add it as a config variable, and enable it by default

Rel flosch/pongo2#261

@sixcolors
Copy link
Member

sixcolors commented Jan 8, 2024

So docs are non existent for pongo2. But https://github.com/flosch/pongo2/blob/c84aecb5fa79a9c0feec284a7bf4f0536c6a6e99/template_tests/autoescape.tpl -> https://github.com/flosch/pongo2/blob/c84aecb5fa79a9c0feec284a7bf4f0536c6a6e99/template_tests/autoescape.tpl.out suggests it can be done in the template.

I would set it to true in the django.go and let them use disable in the template.

we could add a config option or not. But secure by default on templates would be my preference.

@gaby
Copy link
Member

gaby commented Jan 8, 2024

@sixcolors Agree! I will work on a PR

@gaby gaby self-assigned this Jan 8, 2024
@bastianwegge
Copy link
Author

Hey @gaby, we went with something completely different because of the security issues. Rene suggested to open an issue so this wouldn't go unnoticed.

@gaby
Copy link
Member

gaby commented Jan 8, 2024

I plan on updating all the unit-tests today. The output is quite different that without escaping!

@sixcolors
Copy link
Member

sixcolors commented Jan 8, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
☢️ Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants