베타 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는 전체 코드베이스에서 취약한 패턴을 찾아냅니다.