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 V3: avoid leaking information through expandable fields #11381

Merged
merged 3 commits into from
Jul 9, 2024

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Jun 4, 2024

There are still more things to do, but first I'm removing the ones that aren't documented, so this shouldn't be a breaking change, and the information from those fields can already be obtained from the main object or from other endpoints, and if another user with lower permissions was relying on those fields, that was actually a bug.

Ref https://github.com/readthedocs/readthedocs-corporate/issues/1736.

Tests are on .com.

Expandable fields may look cool, but once you have to deal with permissions, they are a pain. Sorry, had to vent.

There are still more things to do, but first I'm removing the ones
that aren't documented, so this shouldn't be a breaking change,
and the information from those fields can already be obtained
from the main object, and if another user with lower permissions was relying on those
fields, that was actually a bug.

Ref readthedocs/readthedocs-corporate#1736.

Expandable fields may look cool, but once you have to deal with
permissions, they are a pain. Sorry, had to vent.
@stsewd stsewd requested a review from a team as a code owner June 4, 2024 22:14
@stsewd stsewd requested a review from humitos June 4, 2024 22:14
# NOTE: we cannot have a Project with multiple organizations.
{"source": "organizations.first"},
),
# NOTE: we are leaking the slugs of all teams linked to this project
# to anyone with access to this prtoject. It's only the slug, but still.
"teams": (
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 think we can just have a teams method field (expanded by default, but with all the correct permissions checked) or a projects/{project}/teams/ endpoint.

Copy link
Member

Choose a reason for hiding this comment

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

I understand it isn't possible to have permission check on expandable fields, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, it's hard/impossible to filter related fields of an object using expandable fields. This is since the related field doesn't know about the current user or whatever checks we need, and we can't override that.

We could implement our own expandable fields, but in a more limited way, like just for detail endpoints (implementing the checks on list views may have an impact on performance), and without recursion (just allow expanding one level).

This also reminds me of this post about graphql https://bessey.dev/blog/2024/05/24/why-im-over-graphql/

expandable_fields = {
"projects": (ProjectSerializer, {"many": True}),
# TODO: we are leaking all teams and its members to anyone who is
# an admin member of the organization.
"teams": (TeamSerializer, {"many": True}),
Copy link
Member Author

Choose a reason for hiding this comment

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

Similar here, having another endpoint will be easier organization/{organization}/teams, similar to organization/{organization}/projects.

@humitos
Copy link
Member

humitos commented Jul 8, 2024

Expandable fields may look cool, but once you have to deal with permissions, they are a pain. Sorry, had to vent.

😂

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.

This looks fine for now 👍🏼

Expandable fields are a good feature because we can expose a lot of relevant data on the same endpoint without compromising it by making it pretty slow (some queries could perform slow) --in case we return all the same data by default.

We've been talking more about APIv3 in the last weeks since we are using it more from the new dashboard. It would be good to have a conversation around APIv3 soon, and decide a path to move forward around this and other limitations we've found:

  • Expandable fields
  • Allow public list endpoints without API token
  • Endpoint missing fields
  • Missing endpoints
  • ... others

# NOTE: we cannot have a Project with multiple organizations.
{"source": "organizations.first"},
),
# NOTE: we are leaking the slugs of all teams linked to this project
# to anyone with access to this prtoject. It's only the slug, but still.
"teams": (
Copy link
Member

Choose a reason for hiding this comment

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

I understand it isn't possible to have permission check on expandable fields, right?

@stsewd stsewd merged commit 3456794 into main Jul 9, 2024
8 checks passed
@stsewd stsewd deleted the avoid-leaking-info-through-expandable-fields branch July 9, 2024 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants