# Improper Verification of Cryptographic Signature (CWE-347) The product does not verify, or incorrectly verifies, the cryptographic signature for data. **Stack:** Python - Prevalence: 高 频繁被利用 - Impact: 关键 1 条严重级别为关键的规则 - Prevention: 已记录 4 个修复示例 **OWASP:** Cryptographic Failures (A02:2021-Cryptographic Failures) - #2 ## Description Cryptographic signatures are used to verify the authenticity and integrity of data. When signature verification is missing or incorrectly implemented, attackers can forge or tamper with data. ## Prevention 基于 2 条 Shoulder 检测规则的 Improper Signature Verification 预防策略。 ### Python Load JWT secret from environment and explicitly specify allowed algorithms Always specify allowed algorithms explicitly when decoding JWT tokens ## Warning Signs - [HIGH] JWT implementation has security vulnerabilities - [HIGH] JWT security issues in FastAPI applications including: - Weak or hardcoded secrets - Missing algorit - [CRITICAL] JWT tokens decoded without algorithm verification or accepting the 'none' algorithm, allowing token ## Consequences - 绕过保护机制 - 执行未授权代码 - 修改应用程序数据 ## Mitigations - 在信任数据之前始终验证签名 - 对签名验证使用经过充分测试的加密库 - 对 JWT,始终验证签名并校验算法 ## Detection - Total rules: 4 - Critical: 1 - Languages: python, go, javascript, typescript ## Rules by Language ### Python (2 rules) - **FastAPI JWT Security Issues** [HIGH]: Detects JWT security issues in FastAPI applications including: - Weak or hardcoded secrets - Missing algorithm verification - Insufficient token validation - Insecure token storage patterns - Remediation: Load JWT secret from environment and explicitly specify the algorithm. ```python from pydantic_settings import BaseSettings from jose import jwt class Settings(BaseSettings): SECRET_KEY: str ALGORITHM: str = "HS256" settings = Settings() def decode_token(token: str): return jwt.decode(token, settings.SECRET_KEY, algorithms=[settings.ALGORITHM]) ``` Learn more: https://shoulder.dev/learn/python/cwe-347/jwt-security - **JWT Algorithm Confusion Attack** [CRITICAL]: Detects JWT tokens decoded without algorithm verification or accepting the 'none' algorithm, allowing token forgery. - Remediation: Always specify allowed algorithms explicitly when decoding JWT tokens. ```python payload = jwt.decode(token, SECRET_KEY, algorithms=['HS256']) ``` Learn more: https://shoulder.dev/learn/python/cwe-347/jwt-algorithm-confusion