From 468ed22a26a543c25e412871a60fe8be2011e677 Mon Sep 17 00:00:00 2001 From: luoshuijs Date: Sat, 26 Aug 2023 18:19:00 +0800 Subject: [PATCH] :sparkles: Mask sensitive information in player id --- modules/gacha_log/log.py | 3 ++- modules/pay_log/log.py | 3 ++- plugins/genshin/abyss.py | 3 ++- plugins/genshin/avatar_list.py | 3 ++- plugins/genshin/daily/material.py | 9 +++++---- plugins/genshin/daily_note.py | 3 ++- plugins/genshin/ledger.py | 3 ++- plugins/genshin/player_cards.py | 3 ++- plugins/genshin/sign.py | 2 +- plugins/genshin/stats.py | 3 ++- utils/uid.py | 9 +++++++++ 11 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 utils/uid.py diff --git a/modules/gacha_log/log.py b/modules/gacha_log/log.py index ec900f80..01712e80 100644 --- a/modules/gacha_log/log.py +++ b/modules/gacha_log/log.py @@ -41,6 +41,7 @@ from modules.gacha_log.models import ( UIGFModel, ) from utils.const import PROJECT_ROOT +from utils.uid import mask_number if TYPE_CHECKING: from core.dependence.assets import AssetsService @@ -533,7 +534,7 @@ class GachaLog: last_time = data[0].time.strftime("%Y-%m-%d %H:%M") first_time = data[-1].time.strftime("%Y-%m-%d %H:%M") return { - "uid": player_id, + "uid": mask_number(player_id), "allNum": total, "type": pool.value, "typeName": pool_name, diff --git a/modules/pay_log/log.py b/modules/pay_log/log.py index 108d9af0..6e3b4665 100644 --- a/modules/pay_log/log.py +++ b/modules/pay_log/log.py @@ -11,6 +11,7 @@ from simnet.utils.player import recognize_genshin_server from modules.pay_log.error import PayLogAuthkeyTimeout, PayLogInvalidAuthkey, PayLogNotFound from modules.pay_log.models import PayLog as PayLogModel, BaseInfo from utils.const import PROJECT_ROOT +from utils.uid import mask_number try: import ujson as jsonlib @@ -240,7 +241,7 @@ class PayLog: if price_data[i]["count"] > 0 ] return { - "uid": player_id, + "uid": mask_number(player_id), "datas": datas, "bar_data": month_datas, "pie_data": pie_datas, diff --git a/plugins/genshin/abyss.py b/plugins/genshin/abyss.py index 6a12fe14..4173b83c 100644 --- a/plugins/genshin/abyss.py +++ b/plugins/genshin/abyss.py @@ -20,6 +20,7 @@ from core.services.template.models import RenderGroupResult, RenderResult from core.services.template.services import TemplateService from plugins.tools.genshin import CookiesNotFoundError, GenshinHelper from utils.log import logger +from utils.uid import mask_number try: import ujson as jsonlib @@ -220,7 +221,7 @@ class AbyssPlugin(Plugin): render_data["time"] = time render_data["stars"] = total_stars - render_data["uid"] = uid + render_data["uid"] = mask_number(uid) render_data["floor_colors"] = { 1: "#374952", 2: "#374952", diff --git a/plugins/genshin/avatar_list.py b/plugins/genshin/avatar_list.py index ba3e74ae..abf38dee 100644 --- a/plugins/genshin/avatar_list.py +++ b/plugins/genshin/avatar_list.py @@ -20,6 +20,7 @@ from metadata.genshin import AVATAR_DATA from modules.wiki.base import Model from plugins.tools.genshin import CharacterDetails, GenshinHelper from utils.log import logger +from utils.uid import mask_number if TYPE_CHECKING: from telegram import Update @@ -183,7 +184,7 @@ class AvatarListPlugin(Plugin): name_card, avatar, nickname, rarity = await self.get_final_data(client.player_id, user) render_data = { - "uid": client.player_id, # 玩家uid + "uid": mask_number(client.player_id), # 玩家uid "nickname": nickname, # 玩家昵称 "avatar": avatar, # 玩家头像 "rarity": rarity, # 玩家头像对应的角色星级 diff --git a/plugins/genshin/daily/material.py b/plugins/genshin/daily/material.py index 265a8186..89304e99 100644 --- a/plugins/genshin/daily/material.py +++ b/plugins/genshin/daily/material.py @@ -28,6 +28,7 @@ from core.services.template.services import TemplateService from metadata.genshin import AVATAR_DATA, HONEY_DATA from plugins.tools.genshin import CharacterDetails, PlayerNotFoundError, CookiesNotFoundError, GenshinHelper from utils.log import logger +from utils.uid import mask_number try: import ujson as jsonlib @@ -249,7 +250,7 @@ class DailyMaterial(Plugin): client, user_data = await self._get_data_from_user(user) await message.reply_chat_action(ChatAction.TYPING) - render_data = RenderData(title=title, time=time, uid=client.player_id if client else client) + render_data = RenderData(title=title, time=time, uid=mask_number(client.player_id) if client else client) calculator_sync: bool = True # 默认养成计算器同步为开启 for type_ in ["avatar", "weapon"]: @@ -480,9 +481,9 @@ class DailyMaterial(Plugin): results = await asyncio.gather(*task_list, return_exceptions=True) # 等待所有任务执行完成 for result in results: if isinstance(result, TimeoutException): - notice_text = f"{result.__class__.__name__} 图标素材下载过程中请求超时.\n有关详细信息,请查看日志" + notice_text = "图标素材下载过程中请求超时\n有关详细信息,请查看日志" elif isinstance(result, Exception): - notice_text = f"{result.__class__.__name__} 图标素材下载过程中发生异常.\n有关详细信息,请查看日志" + notice_text = "图标素材下载过程中发生异常\n有关详细信息,请查看日志" break try: await message.edit_text(notice_text) @@ -520,7 +521,7 @@ class AreaData(BaseModel): class RenderData(BaseModel): title: str # 页面标题,主要用于显示星期几 time: str # 页面时间 - uid: Optional[int] = None # 用户UID + uid: Optional[str] = None # 用户UID character: List[AreaData] = [] # 角色数据 weapon: List[AreaData] = [] # 武器数据 diff --git a/plugins/genshin/daily_note.py b/plugins/genshin/daily_note.py index f88ba74d..ea517554 100644 --- a/plugins/genshin/daily_note.py +++ b/plugins/genshin/daily_note.py @@ -11,6 +11,7 @@ from core.services.template.models import RenderResult from core.services.template.services import TemplateService from plugins.tools.genshin import GenshinHelper from utils.log import logger +from utils.uid import mask_number if TYPE_CHECKING: from simnet import GenshinClient @@ -62,7 +63,7 @@ class DailyNotePlugin(Plugin): transformer_recovery_time = daily_info.transformer_recovery_time.strftime("%m-%d %H:%M") render_data = { - "uid": client.player_id, + "uid": mask_number(client.player_id), "day": day, "resin_recovery_time": resin_recovery_time, "current_resin": daily_info.current_resin, diff --git a/plugins/genshin/ledger.py b/plugins/genshin/ledger.py index fda6b2b2..390eb626 100644 --- a/plugins/genshin/ledger.py +++ b/plugins/genshin/ledger.py @@ -13,6 +13,7 @@ from core.services.template.models import RenderResult from core.services.template.services import TemplateService from plugins.tools.genshin import GenshinHelper from utils.log import logger +from utils.uid import mask_number if TYPE_CHECKING: from telegram import Update @@ -55,7 +56,7 @@ class LedgerPlugin(Plugin): return f"{round(amount / 10000, 2)}w" if amount >= 10000 else amount ledger_data = { - "uid": client.player_id, + "uid": mask_number(client.player_id), "day": diary_info.month, "current_primogems": format_amount(diary_info.month_data.current_primogems), "gacha": int(diary_info.month_data.current_primogems / 160), diff --git a/plugins/genshin/player_cards.py b/plugins/genshin/player_cards.py index d1df1732..19ad123c 100644 --- a/plugins/genshin/player_cards.py +++ b/plugins/genshin/player_cards.py @@ -37,6 +37,7 @@ from utils.enkanetwork import RedisCache from utils.helpers import download_resource from utils.log import logger from utils.patch.aiohttp import AioHttpTimeoutException +from utils.uid import mask_number if TYPE_CHECKING: from enkanetwork import CharacterInfo, EquipmentsStats @@ -486,7 +487,7 @@ class RenderTemplate: artifact_total_score_label = r[0] data = { - "uid": self.uid, + "uid": mask_number(self.uid), "character": self.character, "stats": await self.de_stats(), "weapon": self.find_weapon(), diff --git a/plugins/genshin/sign.py b/plugins/genshin/sign.py index f8d25751..0a8e7b29 100644 --- a/plugins/genshin/sign.py +++ b/plugins/genshin/sign.py @@ -122,7 +122,7 @@ class Sign(Plugin): not filters.ChatType.PRIVATE.filter(message), ) reply_message = await message.reply_text( - f"UID {exc.uid} 签到失败,触发验证码风控,请尝试点击下方按钮重新签到", allow_sending_without_reply=True, reply_markup=button + "签到失败,触发验证码风控,请尝试点击下方按钮重新签到", allow_sending_without_reply=True, reply_markup=button ) if filters.ChatType.GROUPS.filter(reply_message): self.add_delete_message_job(reply_message) diff --git a/plugins/genshin/stats.py b/plugins/genshin/stats.py index e7931459..83a389ff 100644 --- a/plugins/genshin/stats.py +++ b/plugins/genshin/stats.py @@ -11,6 +11,7 @@ from core.services.template.models import RenderResult from core.services.template.services import TemplateService from plugins.tools.genshin import CookiesNotFoundError, GenshinHelper from utils.log import logger +from utils.uid import mask_number if TYPE_CHECKING: from telegram import Update @@ -77,7 +78,7 @@ class PlayerStatsPlugins(Plugin): user_info = user_info.copy(deep=True) data = { - "uid": uid, + "uid": mask_number(uid), "info": user_info.info, "stats": user_info.stats, "explorations": user_info.explorations, diff --git a/utils/uid.py b/utils/uid.py new file mode 100644 index 00000000..75a91b27 --- /dev/null +++ b/utils/uid.py @@ -0,0 +1,9 @@ +import re + + +def mask_number(number): + number_str = str(number) + if len(number_str) == 9: + masked_number = re.sub(r"(\d{2})(\d{4})(\d{3})", r"\1****\3", number_str) + return masked_number + return "Invalid input"