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] "&" gets translated to "&" when creating new company #3500

Closed
2 of 3 tasks
eeintech opened this issue Aug 8, 2022 · 20 comments
Closed
2 of 3 tasks

[BUG] "&" gets translated to "&" when creating new company #3500

eeintech opened this issue Aug 8, 2022 · 20 comments
Labels
question This is a question user interface User interface
Milestone

Comments

@eeintech
Copy link
Contributor

eeintech commented Aug 8, 2022

Please verify that this bug has NOT been raised before.

  • I checked and didn't find similar issue

Describe the bug*

See title

Steps to Reproduce

  1. Create new company
  2. Use "&" symbol in the name
  3. Click submit
  4. Name shows "&" in the name instead of "&"

Expected behavior

"&" should stay as-is

Deployment Method

  • Docker
  • Bare metal

Version Information

InvenTree-Version: 0.9.0 dev
Django Version: 3.2.15
Commit Hash: 964d674
Commit Date: 2022-08-08
Database: postgresql
Debug-Mode: False
Deployed using Docker: True
Active plugins: False

Relevant log output

No response

@eeintech eeintech added bug Identifies a bug which needs to be addressed question This is a question triage:not-checked Item was not checked by the core team labels Aug 8, 2022
@matmair matmair removed the bug Identifies a bug which needs to be addressed label Aug 8, 2022
@matmair
Copy link
Member

matmair commented Aug 8, 2022

@eeintech this is a security measure to protect against CSRF/XSS as the symbol can be used in a scripting context. I am afraid it will have to stay that way as changing it would make us vulnerable again.
Ref: GHSA-rm89-9g65-4ffr

@matmair matmair removed the triage:not-checked Item was not checked by the core team label Aug 8, 2022
@matmair
Copy link
Member

matmair commented Aug 8, 2022

Also please add the version information to all bug reports. The demo is a moving target

@eeintech
Copy link
Contributor Author

eeintech commented Aug 8, 2022

I see... not ideal, some company names are using this symbol (and maybe others).

I don't understand how would it make our instances vulnerable for this kind of attack as most (I hope all) are behind firewalls/VPN, can you explain?

A work around would be to display & instead of & using the translation files?
Can an API GET return "&" while POST keep the security fix?

@SchrodingersGat
Copy link
Member

@eeintech I get the frustration, the current solution is not ideal, but is a compromise to prevent a malicious user from inserting XSS attack into another users browser.

Data gets sanitized on the server and then again when rendering. This double sanitization step makes the "chain of data" something like:

Black & Decker -> Black & Decker -> Black & Decker

There is probably something that can be done about this, would require a bit of a deep dive to understand all the edge cases. There are multiple places where data gets rendered (in different ways):

  • HTML templates
  • Via javascript (e.g. API forms)
  • tables (using bootstrap-table)

Each would need separate consideration.

@SchrodingersGat SchrodingersGat added the user interface User interface label Aug 8, 2022
@SchrodingersGat SchrodingersGat added this to the 0.9.0 milestone Aug 8, 2022
@SchrodingersGat
Copy link
Member

@matmair I can see the appeal of keeping data "as entered" by the user wherever possible. Having e.g. Black & Decker in the database is wrong and what happens when the user exports data e.g to excel?

I think we should look at augmenting our CleanMixin class somewow:

class CleanMixin():

Interesting thread: mozilla/bleach#192

@SchrodingersGat
Copy link
Member

SchrodingersGat commented Aug 9, 2022

Another issue - the "markdown" notes fields get corrupted if you try to add a "blockquote" > character:

image

image

@eeintech
Copy link
Contributor Author

eeintech commented Aug 9, 2022

@SchrodingersGat Thanks for looking into this. What about pre-existing names in 0.7.x instances? Are they all converted for users who upgrade to 0.8.0? Would they create this security issue if not?

Can company added through Admin section be allowed to carry this symbol?

@SchrodingersGat
Copy link
Member

I would imagine that (if we can work out a fix here) it would only apply to new fields. Any instances of invalid characters would need to be manually updated.

Can company added through Admin section be allowed to carry this symbol?

Yes, you can adjust it this way. However it will display incorrectly if you ever edit the company again.

@SchrodingersGat
Copy link
Member

@eeintech
Copy link
Contributor Author

eeintech commented Aug 9, 2022

Useful reference: https://benhoyt.com/writings/dont-sanitize-do-escape/

This article makes a lot of sense, I would vote to rethink the strategy of sanitizing as it compromises the database data with removing or replacing special chars. Again InvenTree instances are not public facing and I trust the people I work with, I don't see how this solve any security breach if the breach doesn't exist in the first place.

@matmair
Copy link
Member

matmair commented Aug 9, 2022

We run a lot of the user input straight into sql queries (through all the Django ORM but the endresult is the same). I discovered this when I reviewed some of the more common attack surfaces.
So escaping is nice but leaves us open to SQL injection and possibly a few cross-server things in the backend too.
As the sanatizing is transparent I do not really see a problem with it. The big enterprise PLM/ERP at work does not even let me use a backtick or ampersand anywhere.

Again InvenTree instances are not public facing

That is not the case. If you know how to it takes only a few minutes. The hardcoded identifier in the base /api path does not help with that

I trust the people I work with, I don't see how this solve any security breach if the breach doesn't exist in the first place.

This is not how modern security works and I hope whoever runs IT/OT sec at your workplace does not think like that. There are always Joiner / Mover in an org that are not really checked. One malicous data entry later you have a permantent shell in the network. Depending on the setup possibly even in the managment plane.
With educational institutions using InvenTree I would be really against removing security features because you trust your coworkers.

The other solution is the just remove the second and third sanitzion layers by marking the strings as safe and adding validations to charfields that stop user from inputting data that will be sanitzied. That is more work but cleaner.
#2789 would solve this issue as proper input validation (before send) is standard.

@eeintech
Copy link
Contributor Author

So escaping is nice but leaves us open to SQL injection and possibly a few cross-server things in the backend too.

I am a user willing to live with that, what are my options?

All my half-baked arguments before are meant to show that I care about conserving the special chars/symbols and am willing to put our security to risk (this is my own choice and I will not hold InvenTree team responsible for that).
Please tell me how to do it, even if it takes a custom patch to be applied at every update.

Thanks.

@SchrodingersGat
Copy link
Member

@eeintech I think it will depend a lot on what we decide on #3503

@matmair
Copy link
Member

matmair commented Aug 10, 2022

I am not going to give instruction on how to break essential security measures but maybe some else is willing to.
We can not assume ppl understand the architectural implications of removing XSS protections. You probably do but if the first thing google shows when searching for special characters is an instruction how to break your instances neck ppl will do that asap.

@SchrodingersGat
Copy link
Member

am a user willing to live with that

We are not devs willing to support that ;)

@matmair
Copy link
Member

matmair commented Aug 10, 2022

@eeintech dont get me wrong, we will find a way to support your case. It will just not be by breaking security.

@eeintech
Copy link
Contributor Author

@eeintech dont get me wrong, we will find a way to support your case. It will just not be by breaking security.

Great to hear. Btw this is not "my case" but I imagine applies to many users (most of them probably haven't noticed yet), I got word of this in Ki-nTree actions else I would not have stumbled on this anytime soon.

I am not going to give instruction on how to break essential security measures but maybe some else is willing to.
We can not assume ppl understand the architectural implications of removing XSS protections. You probably do but if the first thing google shows when searching for special characters is an instruction how to break your instances neck ppl will do that asap.

I do not understand enough about security to argue, but data integrity is more dear to me than security as I'm an optimistic and believe in people, at least the ones I work with (as we are a tiny company). I know it might be hard to grasp when sitting on the other side...

We are not devs willing to support that ;)

As long as you're not devs willing to compromise the integrity of our databases, I'm fine with that!

@matmair
Copy link
Member

matmair commented Aug 10, 2022

The database integrity is fine - there are just additional input rules.

@eeintech
Copy link
Contributor Author

eeintech commented Aug 10, 2022

How is the data integrity fine if you start replacing special chars & or < with 4/5-chars &amp; or &lt; inside parts, company, etc. names? Then it gets way more complicated to find things, scripting, etc.

@eeintech
Copy link
Contributor Author

On my side #3503 fixes it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question This is a question user interface User interface
Projects
None yet
Development

No branches or pull requests

3 participants