jazzband / django-smart-selects

chained and grouped selects for django forms
https://django-smart-selects.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.11k stars 348 forks source link

Security checking for model-fields breaks use of form-fields only #213

Open optiz0r opened 7 years ago

optiz0r commented 7 years ago

Checklist

Steps to reproduce

  1. Update to 1.5.x

Actual behavior

403 prevents chaining from working

Expected behavior

Chaining to still work

Explanation

The changes in 051ea42 have completely broken my (perhaps niche?) use-case. My models only contain the foreign key that is at the end of the chain, rather than all the foreign keys for each step of the chain. This was a deliberate decision to avoid storing duplicate information in the database since my models are modified by both webui but also via REST API. As such I don't use the Chained model fields at all, only the Chained Form fields, which I've been manually adding to forms.

An example chain is Continent->Country->Address->Item->Child Item. My Child Item contains only an item_id field, not also continent_id, country_id, address_id fields.

The two potential database integrity issues I'm concerned about are:

I don't want to over-complicate my models by adding complex save() logic to check for and update the parents in the chain each time they are modified.

The security changes stop the form fields working completely because every single lookup is now running a 403 since there are no model fields. I'm not concerned about information leakage via this app. I would prefer the specific check for model-fields were optional, and that the security concerns were mitigated by checking for model and object-level permissions instead.

I'm hoping you'll agree that this is a valid use-case and worth supporting. If so, I'll see if I can help with a PR. In the meantime I'm probably going to have to revert back to 1.3.4 and cherry-pick in the specific bugfixes I need.

Edit (by @blag): Fixed checkboxes to actually be Markdown checkboxes.

blag commented 7 years ago

I'm hoping you'll agree that this is a valid use-case and worth supporting.

Yep.

and that the security concerns were mitigated by checking for model and object-level permissions instead

This is, AFAICT, difficult to do in a generic fashion to support all users of django-smart-selects. I think a global option to turn off the model field checking (and default to on) would be a sufficient situation. If users need more complicated permissions checks they can use django-autocomplete-light, which requires much more configuration and custom coding than django-smart-selects.

I'll see if I can help with a PR.

That would be great and very appreciated. Please namespace the global option with SMART_SELECTS_ and default to the more secure option.

blag commented 7 years ago

And if adding tests for the new option aren't too difficult, please add tests for it.