Skip to content

Scope feed share tokens to their owners. Closes #1806 - #1810

Merged
regulartim merged 5 commits into
GreedyBear-Project:developfrom
ABHIGYA0205:fix/share-token-owner-scoping-v2
Nov 4, 2026
Merged

regulartim merged 5 commits into
GreedyBear-Project:developfrom
ABHIGYA0205:fix/share-token-owner-scoping-v2

Conversation

@ABHIGYA0205

@ABHIGYA0205 ABHIGYA0205 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

The feed-share endpoint can produce identical tokens when different users request the same feed filters within the same second. The reason parameter is excluded from the signed data, and ShareToken.token_hash is unique. As a result, a later user’s request can reuse a token record owned by the first user, preventing the later user from listing or revoking that token.

The signing salt is now derived from the creating user’s ID, and token verification uses the owner ID stored on the ShareToken record. A fixed-time regression test uses two non-staff users and verifies distinct tokens, correct ownership, per-user listings, cross-user revoke denial, and each owner’s ability to revoke their own token.

Compatibility: Pre-existing links signed with the old global salt will no longer validate after this change. The maintainer confirmed in #1806 that this invalidation is acceptable for the next major release.

Validation: The PR backend CI lint and Python test steps passed. The two focused modules also passed locally (81 tests).

Related issues

Closes #1806 — Same-second share requests can return a token owned by another user.

Type of change

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).
  • Chore (refactoring, dependency updates, CI/CD changes, code cleanup, docs-only changes).

Checklist

Please complete this checklist carefully. It helps guide your contribution and lets maintainers verify that all requirements are met.

Formalities

  • I have read and understood the rules about how to Contribute to this project.
  • I chose an appropriate title for the pull request in the form: <feature name>. Closes #999
  • My branch is based on develop.
  • The pull request is for the branch develop.
  • I have reviewed and verified any LLM-generated code included in this PR.

Docs and tests

  • I documented my code changes with docstrings and/or comments.
  • I have checked if my changes affect user-facing behavior that is described in the docs. If so, I also included an update to the wiki in the description of this PR.
  • Linter (Ruff) gave 0 errors. If you have correctly installed pre-commit, it does these checks and adjustments on your behalf.
  • I have added tests for the feature/bug I solved.
  • All the tests gave 0 errors.

GUI changes

Ignore this section if you did not make any changes to the GUI.

  • I have provided a screenshot of the result in the PR.
  • I have created new frontend tests for the new component or updated existing ones.

Review process

  • We encourage you to create a draft PR first, even when your changes are incomplete. This way you refine your code while we can track your progress and actively review and help.
  • If you think your draft PR is ready to be reviewed by the maintainers, click the corresponding button. Your draft PR will become a real PR.
  • If your changes decrease the overall tests coverage (you will know after the Codecov CI job is done), you should add the required tests to fix the problem.
  • Every time you make changes to the PR and you think the work is done, you should explicitly ask for a review. After receiving a "change request", address the feedback and click "request re-review" next to the reviewer's profile picture at the top right.

@regulartim regulartim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey @ABHIGYA0205 ! Looks good all in all, thank you! :) Could you take a look at the tests in tests/api/views/test_feeds_advanced_view.py? Some of them still sign with the hardcoded "greedybear-feeds" salt. We should also update them, right?

Comment thread greedybear/consts.py Outdated
Comment on lines +97 to +102

def share_token_salt_for_user(user_id: int) -> str:
"""Derive a signing salt scoped to the user who created a share token."""
return f"{SHARE_TOKEN_SALT}:{user_id}"


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A function in a constants module is a bit out of place, don't you think? Can you think of a better place?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I moved share_token_salt_for_user() into api/share_tokens.py and updated the view and serializer to import it from there. greedybear/consts.py now just holds the salt and max-age constants.

@ABHIGYA0205

ABHIGYA0205 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Yes, I updated those tests to use the user-specific salt helper instead of hardcoding "greedybear-feeds". After merging develop, I reran the focused feed tests locally, and all 85 passed. Let me know if there’s anything else you’d like me to adjust.

@regulartim regulartim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey @ABHIGYA0205 ! I know this is very nit-picky, but I moved the method to models.py . I think that's the best place for it. What do you think? If you are fine with this, we can merge! :)

@ABHIGYA0205

Copy link
Copy Markdown
Contributor Author

yeah @regulartim , I think that makes sense. Since the salt is tied to the token’s owner, keeping it on ShareToken feels like the right place. I’m happy with this change. You can merge it ! :)

@ABHIGYA0205
ABHIGYA0205 marked this pull request as ready for review November 4, 2026 19:46
@regulartim
regulartim merged commit ae4f2e9 into GreedyBear-Project:develop Nov 4, 2026
7 checks passed
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

Successfully merging this pull request may close these issues.

2 participants