Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/modules/video-engine/engines/watermark.engine.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import type { FFmpeg } from "@ffmpeg/ffmpeg";
export interface WatermarkOptions { [key: string]: unknown; }
export async function buildWatermarkArgs(input: string, output: string, opts: WatermarkOptions, ffmpeg?: FFmpeg, files?: File[]): Promise<string[]> {
const text = (opts.text as string) || "HEAVY-TOOLS";
let text = (opts.text as string) || "HEAVY-TOOLS";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Guard opts.text type before sanitization to prevent runtime crashes.

At Line 4, as string does not coerce runtime values. If opts.text is a truthy non-string, Line 8 will throw.

πŸ”§ Suggested fix
-  let text = (opts.text as string) || "HEAVY-TOOLS";
+  let text = typeof opts.text === "string" ? opts.text : "HEAVY-TOOLS";
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let text = (opts.text as string) || "HEAVY-TOOLS";
let text = typeof opts.text === "string" ? opts.text : "HEAVY-TOOLS";
πŸ€– Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/modules/video-engine/engines/watermark.engine.ts` at line 4, The code
assumes opts.text is a string when assigning to the local variable text (let
text = (opts.text as string) || "HEAVY-TOOLS"), which can throw later when
sanitizing non-string values; change the assignment to first guard the runtime
type (e.g., check typeof opts.text === "string") and only use opts.text if it's
a string, otherwise fall back to the default "HEAVY-TOOLS" before any
sanitization; update references to text and any subsequent sanitization logic in
watermark.engine.ts (the text variable and opts.text usage) so non-string inputs
are safely handled.


// Sanitize input for FFmpeg drawtext filter injection
text = text
.replace(/\\/g, '\\\\')
.replace(/:/g, '\\:')
.replace(/'/g, "'\\''");

const posX = (opts.posX as string) || "10";
const posY = (opts.posY as string) || "10";
const fontSize = (opts.fontSize as number) || 24;
Expand Down