Skip to content

[Security] sanitizeMimeType regex should be anchored and case-insensitive #9795

@ekson73

Description

@ekson73

Summary

In src/media-understanding/apply.ts, the sanitizeMimeType function's regex is not anchored at the end, which could allow malicious suffixes. Additionally, MIME types are case-insensitive per RFC standards.

Impact

Severity: Medium (8/10)
Type: Security - Input validation

Current Behavior

const trimmed = value.trim().toLowerCase();
const match = trimmed.match(/^([a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]+)/);
return match?.[1];

Suggested Fix

const trimmed = value.trim();
const match = trimmed.match(/^([a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]+)(?:;.*)?$/i);
return match?.[1].toLowerCase();

This:

  1. Anchors the regex at the end ($)
  2. Makes it case-insensitive (/i)
  3. Handles optional parameters ((?:;.*)?)

Source

Identified by Qodo AI code review.

Files Affected

  • src/media-understanding/apply.ts (lines 96-106)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsecuritySecurity documentation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions