Skip to content

Commit

Permalink
fix: prevent recipe sharing from different group (#4929)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuchenpirat authored Jan 22, 2025
1 parent c74ba0e commit 8cd2da0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mealie/routes/shared/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from functools import cached_property

from fastapi import HTTPException
from pydantic import UUID4

from mealie.routes._base import BaseUserController, controller
Expand Down Expand Up @@ -30,6 +31,11 @@ def get_all(self, recipe_id: UUID4 | None = None):

@router.post("", response_model=RecipeShareToken, status_code=201)
def create_one(self, data: RecipeShareTokenCreate) -> RecipeShareToken:
# check if recipe group id is the same as the user group id
recipe = self.repos.recipes.get_one(data.recipe_id, "id")
if recipe is None or recipe.group_id != self.group_id:
raise HTTPException(status_code=404, detail="Recipe not found in your group")

save_data = RecipeShareTokenSave(**data.model_dump(), group_id=self.group_id)
return self.mixins.create_one(save_data)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,12 @@ def test_recipe_share_tokens_delete_one(api_client: TestClient, unique_user: Tes
token = database.recipe_share_tokens.get_one(token.id)

assert token is None


def test_share_recipe_from_different_group(api_client: TestClient, unique_user: TestUser, g2_user: TestUser, slug: str):
database = unique_user.repos
recipe = database.recipes.get_one(slug)
assert recipe

response = api_client.post(api_routes.shared_recipes, json={"recipeId": str(recipe.id)}, headers=g2_user.token)
assert response.status_code == 404

0 comments on commit 8cd2da0

Please sign in to comment.