T09 · Insecure Skill Coding Practices
- Location
ad_manager.py:78- Finding
Reusable Authentication Cookies Stored in Plaintext
- Content
View full analysis
Vulnerability Details
File Location:
ad_manager.py:29-42,ad_manager.py:61-85, andad_manager.py:106-133
Vulnerability Type: Plaintext storage of sensitive authentication data
Risk Level: HighVulnerable Code
python @dataclass class AdAccount: """广告账户数据结构""" id: str platform: str account_type: str name: str cookies: List[Dict] created_at: float last_used: float balance: float = 0.0 daily_cost: float = 0.0 budget: float = 0.0 status: str = "normal" # normal, warning, errorpython self.accounts_file = self.storage_dir / "accounts.json" self.accounts: Dict[str, AdAccount] = {} # 加载已保存的账户 self._load_accounts() def _load_accounts(self): """从文件加载账户数据""" if self.accounts_file.exists(): try: with open(self.accounts_file, 'r', encoding='utf-8') as f: data = json.load(f) for account_id, account_data in data.items(): self.accounts[account_id] = AdAccount(**account_data) except Exception as e: print(f"加载账户数据失败: {e}") def _save_accounts(self): """保存账户数据到文件""" data = {} for account_id, account in self.accounts.items(): data[account_id] = asdict(account) with open(self.accounts_file, 'w', encoding='utf-8') as f: json.dump(data, f, ensure_ascii=False, indent=2)python def add_account(self, platform: Platform, account_type: AccountType, name: str, cookies: List[Dict]) -> str: """ 添加新账户 """ account_id = f"{platform.value}_{account_type.value}_{int(time.time())}" account = AdAccount( id=account_id, platform=platform.value, account_type=account_type.value, name=name, cookies=cookies, created_at=time.time(), last_used=time.time() ) self.a ...[truncated 3143 chars]- Remediation
View remediation
Remediation Suggestions
- Store cookies in an operating-system credential manager or a dedicated encrypted secret store. Keep only an opaque credential reference in
accounts.json. - If local file storage is unavoidable, encrypt cookie values with authenticated encryption. Protect the encryption key separately from the encrypted data.
- Create credential files with explicit owner-only permissions, such as mode
0600on POSIX systems, rather than relying on the process umask. - Use atomic writes through a securely created temporary file, apply restrictive permissions before writing secrets, and atomically replace the destination.
- Retain only cookies strictly required for authentication and discard unrelated tracking or cross-domain cookies.
- Exclude credential files from source control, diagnostic archives, logs, and ordinary backups.
- Add explicit logout and credential-revocation functionality so deletion also invalidates the server-side session where supported.
- Validate cookie expiration before reuse and require reauthentication for expired or suspicious sessions.
- Remove the standalone plaintext
save_cookies_to_file()helper or replace it with the same protected secret-storage mechanism. - Add automated tests that verify credential files are encrypted, permission-restricted, and never included in ordinary account metadata.
- Store cookies in an operating-system credential manager or a dedicated encrypted secret store. Keep only an opaque credential reference in
