ベータ Shoulder はベータ版です — 結果が誤っている場合があります。皆さまのフィードバックが次に修正する内容を決定します。 フィードバックを送る
✍️

Improper Verification of Cryptographic Signature

🛡️ 4 件のルールが検出します

Improper Verification of Cryptographic Signature

The product does not verify, or incorrectly verifies, the cryptographic signature for data.

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.

普及度
頻繁に悪用される
影響度
クリティカル
1 件の重大度クリティカルなルール
予防
文書化済み
4 件の修正例
2 予防
2 予防

この脆弱性の修正方法

4 件の Shoulder 検出ルールに基づく Improper Signature Verification の予防策。

FastAPI JWT Security Issues HIGH

Load JWT secret from environment and explicitly specify allowed algorithms

+11 -6 python
- from jose import jwt
- 
- SECRET = "my-secret-key"
- 
- def decode_token(token: str):
-     return jwt.decode(token, SECRET)
+ 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])
  
JWT Algorithm Confusion Attack CRITICAL

Always specify allowed algorithms explicitly when decoding JWT tokens

+13 -7 python
  import jwt
- from flask import request
- 
- @app.route('/api/user')
- def get_user():
-     token = request.headers.get('Authorization')
-     payload = jwt.decode(token, SECRET_KEY, verify=False)
-     return {'user': payload['user_id']}
+ import os
+ from flask import request
+ 
+ SECRET_KEY = os.environ['JWT_SECRET']
+ 
+ @app.route('/api/user')
+ def get_user():
+     token = request.headers.get('Authorization')
+     try:
+         payload = jwt.decode(token, SECRET_KEY, algorithms=['HS256'])
+         return {'user': payload['user_id']}
+     except jwt.InvalidTokenError:
+         return {'error': 'Invalid token'}, 401
  
JWT Security Vulnerabilities HIGH

Validate JWT algorithm explicitly, use strong secrets, and set expiration

+4 -1 go
  func parseToken(tokenString string) (*jwt.Token, error) {
      return jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
-         return []byte("secret"), nil
+         if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
+             return nil, fmt.Errorf("unexpected method: %v", token.Header["alg"])
+         }
+         return []byte(os.Getenv("JWT_SECRET")), nil
      })
  }
  
JWT Decode Without Verification HIGH

Use jwt.verify() instead of jwt.decode() to validate token signatures

+3 -1 javascript
- const decoded = jwt.decode(token);
+ const decoded = jwt.verify(token, process.env.JWT_SECRET, {
+   algorithms: ['RS256']
+ });
  req.user = decoded;
  

主要なプラクティス

  • Use of jwt
3 検出
3 検出

コードの脆弱性を見つける

Shoulderを使用してコードのImproper Verification of Cryptographic Signatureパターンをスキャンしましょう。 4 ルール.

ターミナル
# Scan with Shoulder CLI
npx @shoulderdev/cli trust --cwe=347

# Or scan entire project
npx @shoulderdev/cli trust .

検出ルール (4)

4 警告サイン
4 警告サイン

コードレビューで注目すべき点

これらのパターンはImproper Verification of Cryptographic Signatureの潜在的な脆弱性を示しています。コードレビューとセキュリティ監査中に探してください。

🟠
JWT implementation has security vulnerabilities fastapi-jwt-security
🟠
JWT security issues in FastAPI applications including: - Weak or hardcoded secrets - Missing algorit fastapi-jwt-security
🔴
JWT tokens decoded without algorithm verification or accepting the 'none' algorithm, allowing token python-jwt-algorithm-confusion
🔍

コードベースをスキャン: Improper Verification of Cryptographic Signature

Shoulder CLI はコードベース全体から脆弱なパターンを見つけます。