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

Security Issue - Data Leak with django-select2 #230

Open
andyp05 opened this issue May 20, 2024 · 0 comments
Open

Security Issue - Data Leak with django-select2 #230

andyp05 opened this issue May 20, 2024 · 0 comments

Comments

@andyp05
Copy link

andyp05 commented May 20, 2024

Using django-multitenant and django-select2.
I am adding a widget to a form because I need to filter on the deleted field and by default select2 will pull all records.

class Contacts(TenantModel):
    account = models.ForeignKey(Accounts, on_delete=models.CASCADE, related_name='cont_account', db_index=False)
    name = models.CharField(max_length=128, db_index=True)
    deleted = models.DateTimeField(null=True, blank=True)

    class TenantMeta:
        tenant_field_name = "account_id"

class ContactWidget(ModelSelect2Widget):
    search_fields = ['name__icontains']
    queryset = Contacts.objects.filter(deleted__isnull=True).order_by('name')

In the ModelForm containing the FK link to Contacts I add the widget in the Meta section:

    class Meta:
        model = ParentModel
        fields = [...,  'client_contact', 'deleted']

        widgets = {
            'client_contact': ContactWidget(attrs={'style': 'width:341px'}),
           ....
       }

The form displays fine and the select2 dropdown shows all the entries as expected if I have only one tenant.
The queryset in the ModelSelect2Widget does not filter on account id.

From the logger:

05/20/2024 09:19:22 AM | DEBUG | (0.000) SELECT "contacts"."id", "contacts"."account_id", "contacts"."name"  WHERE "contacts"."deleted" IS NULL ORDER BY "contacts"."name" ASC LIMIT 2; args=(); alias=default | utils.py:151 debug_sql()
TENANT_STRICT_MODE = True

Did not flag the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant