mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-01-15 15:48:05 +00:00
fix(security): prevent log injection in WebSocket message logging
Sanitize WebSocket messages before logging to prevent log injection attacks. User-controlled data from WebSocket messages could contain newline characters that allow forging fake log entries. Changes: - Convert message object to JSON string and remove newlines/carriage returns - Use format specifier (%s) for safe string interpolation - Applied fix to providers/WebSocketProvider.tsx and hooks/useWebsockets.ts Resolves CodeQL security alert js/log-injection Co-authored-by: GitHub Copilot Autofix <noreply@github.com>
This commit is contained in:
@@ -96,7 +96,9 @@ export const useWebSocket = ({
|
||||
| Record<string, string>
|
||||
| undefined; // Arguments are Dictionary<string, string>
|
||||
|
||||
console.log("[WS] ~ ", lastMessage);
|
||||
// Sanitize output to avoid log injection
|
||||
const msgStr = JSON.stringify(lastMessage).replaceAll(/[\n\r]/g, " ");
|
||||
console.log("[WS] ~ %s", msgStr);
|
||||
|
||||
if (command === "PlayPause") {
|
||||
console.log("Command ~ PlayPause");
|
||||
|
||||
@@ -96,7 +96,9 @@ export const WebSocketProvider = ({ children }: WebSocketProviderProps) => {
|
||||
newWebSocket.onmessage = (e) => {
|
||||
try {
|
||||
const message = JSON.parse(e.data);
|
||||
console.log("[WS] Received message:", message);
|
||||
// Sanitize output to avoid log injection
|
||||
const msgStr = JSON.stringify(message).replaceAll(/[\n\r]/g, " ");
|
||||
console.log("[WS] Received message: %s", msgStr);
|
||||
setLastMessage(message); // Store the last message in context
|
||||
} catch (error) {
|
||||
console.error("Error parsing WebSocket message:", error);
|
||||
|
||||
Reference in New Issue
Block a user