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

Improper Output Neutralization for Logs

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

Improper Output Neutralization for Logs

The product does not neutralize or incorrectly neutralizes output that is written to logs.

Log injection attacks occur when user input is written to log files without proper sanitization. This can allow attackers to forge log entries, inject malicious content, or exploit log analysis tools.

普及度
3 言語をカバー
影響度
ミディアム
レビュー推奨
予防
文書化済み
4 件の修正例
2 予防
2 予防

この脆弱性の修正方法

4 件の Shoulder 検出ルールに基づく Log Injection の予防策。

Log Injection / Log Forging MEDIUM

Strip newlines and control characters from user input before logging

+13 -6 go
  package main
  
  import (
      "log"
      "net/http"
- )
- 
- func handler(w http.ResponseWriter, r *http.Request) {
-     username := r.URL.Query().Get("user")
-     // Vulnerable: user input logged directly
-     log.Printf("Login attempt for user: %s", username)
+     "strings"
+ )
+ 
+ func sanitizeLogInput(s string) string {
+     s = strings.ReplaceAll(s, "\n", "")
+     s = strings.ReplaceAll(s, "\r", "")
+     return s
+ }
+ 
+ func handler(w http.ResponseWriter, r *http.Request) {
+     username := r.URL.Query().Get("user")
+     // Safe: newlines stripped before logging
+     log.Printf("Login attempt for user: %s", sanitizeLogInput(username))
  }
  
Log Injection LOW

Strip newline characters from user input before writing to log files

+1 -1 javascript
  const express = require('express');
  const winston = require('winston');
  const app = express();
  
  app.post('/login', (req, res) => {
-   const username = req.body.username;
+   const username = req.body.username.replace(/[\r\n]/g, '');
    winston.info(`Login attempt: ${username}`);
    res.json({ status: 'ok' });
  });
  
Log Injection MEDIUM

Sanitize user input by stripping CRLF characters before writing to logs

+4 -2 javascript
- app.post('/login', (req, res) => {
-   logger.info(`Login attempt from: ${req.body.username}`);
+ const sanitize = (str) => str.replace(/[\r\n]/g, '').substring(0, 200);
+ 
+ app.post('/login', (req, res) => {
+   logger.info('Login attempt', { username: sanitize(req.body.username) });
  });
  
Log Injection / Log Forging MEDIUM

Use structured logging with separate fields for user data instead of string interpolation

+6 -4 python
  import logging
  from flask import request
  
- @app.route('/login', methods=['POST'])
- def login():
-     username = request.form.get('username')
-     logging.info(f"Login attempt for user: {username}")
+ logger = logging.getLogger(__name__)
+ 
+ @app.route('/login', methods=['POST'])
+ def login():
+     username = request.form.get('username', '')
+     logger.info("Login attempt", extra={'username': username})
      return "OK"
  
3 検出
3 検出

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

Shoulderを使用してコードのImproper Output Neutralization for Logsパターンをスキャンしましょう。 4 ルール.

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

# Or scan entire project
npx @shoulderdev/cli trust .
4 警告サイン
4 警告サイン

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

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

🟡
unsanitized user input flowing into log statements, enabling log forging attacks go-log-injection
🟡
user input flowing directly into log messages without sanitization python-log-injection
🔵
user input flowing to persistent log files without sanitization javascript-log-injection
🔍

コードベースをスキャン: Improper Output Neutralization for Logs

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