From d7da2e133afc7b937bbbaf6ef86e31ae8ecb95d0 Mon Sep 17 00:00:00 2001 From: InfinityPacer <160988576+InfinityPacer@users.noreply.github.com> Date: Mon, 7 Oct 2024 23:37:20 +0800 Subject: [PATCH] feat(security): add cache to wallpaper endpoints to mitigate attacks --- app/utils/web.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/utils/web.py b/app/utils/web.py index 4ab0e877..43340ab2 100644 --- a/app/utils/web.py +++ b/app/utils/web.py @@ -1,5 +1,7 @@ from typing import Optional +from cachetools import TTLCache, cached + from app.utils.http import RequestUtils @@ -73,6 +75,7 @@ class WebUtils: return "" @staticmethod + @cached(cache=TTLCache(maxsize=1, ttl=3600)) def get_bing_wallpaper() -> Optional[str]: """ 获取Bing每日壁纸 @@ -90,6 +93,7 @@ class WebUtils: return None @staticmethod + @cached(cache=TTLCache(maxsize=1, ttl=3600)) def get_bing_wallpapers(num: int = 7) -> Optional[str]: """ 获取7天的Bing每日壁纸