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

API: use restricted serializer for related projects #11820

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Dec 3, 2024

@stsewd stsewd requested a review from a team as a code owner December 3, 2024 21:55
@stsewd stsewd requested a review from humitos December 3, 2024 21:55
model = Project
fields = [
"id",
"name",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should exclude the name from restricted objects as well (restricted organization is the other serializer like this)

Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused about what we talked in our meeting and what we are implementing here. I understood we were going in another direction. Can you explain more your thoughts here and what are the next steps based on the context I've shared?

@@ -736,6 +736,28 @@ def get_admin(self, obj):
return AdminPermission.is_admin(user, obj)


class RestrictedProjectSerializer(serializers.ModelSerializer):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if we name this UnAuthedProjectSerializer or AnonymousProjectSerializer which is more explicit when this serializer is going to be used.

Comment on lines +742 to +746
Stripped version of the ProjectSerializer to be used when including related projects.

This serializer is used to avoid leaking information about a private project through
a public project. Instead of checking if user has access to the project,
we just show the name and slug.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our meeting we talked about differentiating authed from un-authend/anonymous and based on the permissions used the full serializer or the un-authed one. Also, we talked about removing only those sensitive fields, like repo, instead of removing almost everything.

I want to keep as much consistency as possible in the returned objects here to match APIv3 responses.

We are planning to remove all these objects from the Addons API response in readthedocs/addons#356 and make usage of the APIv3 directly. We will need these ProjectSerializer and AnonymousProjectSerializer there as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was about addons in the case where we are leaking the project information if a project is private, but has a public version. This case is about the translation_of/subproject_of fields that are returned with the project, if the related projects are private, but the parent project is public.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this implementation if the parent project is public and the related project is public, we are going to strip all the data as well. That's what I want to avoid.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case, this code is temporal and is going to be removed since the Addons API won't return this data anymore and everything will be retrieved using APIv3 in readthedocs/addons#356. In those endpoints, we will implement auth/anonymous serializers. Do we agree on that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code is temporal and is going to be removed since the Addons API won't return this data anymore and everything will be retrieved using APIv3

Yeah, but this is still a problem for the projects/ endpoint of API v3 where we are still leaking that information.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't reply to the last part of my comment:

In those endpoints, we will implement auth/anonymous serializers. Do we agree on that?

Is that correct? We will those serializers there eventually?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the detail views maybe (if they are really needed by addons), but this is for a related field. We can also check for authz here, but that introduces two extra calls for each object, and that will be leaking authz checks into the serializer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the detail views maybe (if they are really needed by addons),

OK, yeah, we will require the permission checks there 👍🏼

but this is for a related field. We can also check for authz here, but that introduces two extra calls for each object,

Addons will require a few fields on these related objects as well; in particular documentation urls and API links, which I understand you are keeping those in the serializers here. We can probably perform another request to the detail view if it needs more extra data or re-consider adding more fields here.

and that will be leaking authz checks into the serializer.

What "leaking authz checks" means?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably perform another request to the detail view if it needs more extra data or re-consider adding more fields here.

Yeah, that's my idea, just expose the necessary information to avoid doing a separate call /projects/<project>/main-translation/, but also don't expose everything, just enough to query the whole object if needed (the slug in this case).

What "leaking authz checks" means?

Serializers just render an object to json, they shouldn't have authorization checks, those should be done before rendering the object.

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

Successfully merging this pull request may close these issues.

2 participants