# Improper Output Neutralization for Logs (CWE-117) The product does not neutralize or incorrectly neutralizes output that is written to logs. **Stack:** Go - Prevalence: Średnia Pokryto 3 języków - Impact: Średni Zalecany przegląd - Prevention: Udokumentowane 4 przykładów poprawek **OWASP:** Injection (A03:2021-Injection) - #3 ## Description 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. ## Prevention Strategie zapobiegania dla Log Injection oparte na 1 regułach detekcji Shoulder. ### Go Strip newlines and control characters from user input before logging ## Warning Signs - [MEDIUM] unsanitized user input flowing into log statements, enabling log forging attacks ## Consequences - Modyfikacja danych aplikacji - Ukrywanie aktywności - Wykonanie nieautoryzowanego kodu ## Mitigations - Waliduj i sanitizuj wszystkie wejścia przed zapisaniem ich do logów - Stosuj uporządkowane formaty logów oddzielające dane od składni logu - Koduj znaki specjalne podczas zapisywania danych kontrolowanych przez użytkownika do logów ## Detection - Total rules: 4 - Languages: go, javascript, typescript, python ## Rules by Language ### Go (1 rules) - **Log Injection / Log Forging** [MEDIUM]: Detects unsanitized user input flowing into log statements, enabling log forging attacks. - Remediation: Remove newlines and control characters from user input before logging. ```go sanitized := strings.ReplaceAll(userInput, "\n", "") sanitized = strings.ReplaceAll(sanitized, "\r", "") log.Printf("User action: %s", sanitized) ``` Learn more: https://shoulder.dev/learn/go/cwe-117/log-injection