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

Serializer accepts int parameter although allow int lookup is false #65

Closed
frossigneux opened this issue Sep 6, 2021 · 2 comments
Closed
Assignees
Labels

Comments

@frossigneux
Copy link
Contributor

Hello,

I have observed that the serializer converts a int parameter to object, even if int lookup is forbidden.
My serializer is:
foo = serializers.PrimaryKeyRelatedField(pk_field=HashidSerializerCharField(), queryset=Foo.objects.all(), required=False)

Then I have a validate method:
def validate_foo(self, value)

Both integer and string parameter triggers the validate_foo method with the retrieved object in argument.
However, HASHID_FIELD_ALLOW_INT_LOOKUP is False.

This leads to a security hole, where a user can retrieve the integer behind the obfuscated id of its objects.

@nshafer nshafer self-assigned this Sep 10, 2021
@nshafer nshafer added the bug label Sep 10, 2021
@nshafer
Copy link
Owner

nshafer commented Sep 10, 2021

Thank you for the detailed report. I will look into as soon as I can.

@nshafer
Copy link
Owner

nshafer commented Sep 17, 2021

Thanks for catching this... I have never used my own module with any writable DRF APIs, so just hadn't dog-fooded this particular issue, and haven't touched the DRF stuff much since the original release. I have modified HashidSerializerCharField to now disallow int lookups if allow_int_lookup is false.

BTW, in your example you don't pass source_field to HashidSerializerCharField in your PrimaryKeyRelatedField. Probably just in your example, but make sure you're doing such in your actual code per https://github.com/nshafer/django-hashid-field#primary-key-related-fields.

Thanks!

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

No branches or pull requests

2 participants