Skip to content

API V3: use a restricted serializer for when showing org info from a project #11732

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

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions readthedocs/api/v3/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,10 +808,12 @@ class Meta:
"many": True,
},
),
# NOTE: we use a serializer without expandable fields to avoid
# leaking information about the organization through the project.
# NOTE: we use a different serializer with just a subset of fields
# to avoid leaking information about the organization through a public project.
# Users can use the /api/v3/organizations/ endpoint to get more information
# about the organization.
"organization": (
"readthedocs.api.v3.serializers.OrganizationSerializer",
"readthedocs.api.v3.serializers.RestrictedOrganizationSerializer",
# NOTE: we cannot have a Project with multiple organizations.
{"source": "organizations.first"},
),
Expand Down Expand Up @@ -1211,6 +1213,26 @@ class Meta:
)


class RestrictedOrganizationSerializer(serializers.ModelSerializer):

"""
Stripped version of the OrganizationSerializer to be used when listing projects.

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

_links = OrganizationLinksSerializer(source="*")

class Meta:
model = Organization
fields = (
"name",
"slug",
"_links",
)


class RemoteOrganizationSerializer(serializers.ModelSerializer):
class Meta:
model = RemoteOrganization
Expand Down