isFullMediaType incorrectly returns true for media types without top-level type or wildcard type (/png, */png)
Description
isFullMediaType(mediaType) in @ai-sdk/provider-utils is defined to verify whether a media type has a concrete type/subtype format (e.g. image/png) rather than a top-level shorthand (image) or wildcard (image/*).
However, its implementation only checks mediaType.indexOf('/') and whether the subtype is not '*':
export function isFullMediaType(mediaType: string): boolean {
const slashIndex = mediaType.indexOf('/');
if (slashIndex === -1) {
return false;
}
const subtype = mediaType.substring(slashIndex + 1);
return subtype.length > 0 && subtype !== '*';
}
Because it does not validate that the top-level type (the portion before the slash) is non-empty and non-wildcard:
isFullMediaType('/png')returnstrue(top-level type is empty string"").isFullMediaType('*/png')returnstrue(top-level type is wildcard'*').isFullMediaType('*/*')returnsfalse(only because subtype is'*').
In contrast, getTopLevelMediaType('/png') returns "". This causes downstream consumers (e.g. resolveFullMediaType) to treat malformed or wildcard strings as valid full media types instead of falling back to sniffing or erroring cleanly.
Reproduction
import { isFullMediaType } from '@ai-sdk/provider-utils';
console.log(isFullMediaType('/png')); // true (Expected: false)
console.log(isFullMediaType('*/png')); // true (Expected: false)
Proposed Fix
Verify that slashIndex > 0 and that the top-level segment is not '*':
export function isFullMediaType(mediaType: string): boolean {
const slashIndex = mediaType.indexOf('/');
if (slashIndex <= 0) {
return false;
}
const type = mediaType.substring(0, slashIndex);
if (type === '*') {
return false;
}
const subtype = mediaType.substring(slashIndex + 1);
return subtype.length > 0 && subtype !== '*';
}
Identify issue type
Identified as Bug
Confidence: High
Rationale
The issue identifies a specific validation defect in existing SDK behavior, demonstrates incorrect output, and proposes a corrective implementation.
Evidence
isFullMediaType('/png')andisFullMediaType('*/png')returntruedespite lacking a concrete top-level media type.- A concrete reproduction and expected
falseresults are provided. - The incorrect validation can cause downstream consumers to accept malformed or wildcard media types as valid full media types.
Identify bug discovery
Discovery source: discovery:audit (medium confidence).
The report appears to originate from inspecting the SDK’s media-type validation logic and testing edge cases against that implementation. It provides no evidence of discovery through a production application.
- The author quotes and analyzes the implementation of
isFullMediaType. - The report identifies the precise missing checks for an empty or wildcard top-level type.
- It compares behavior with another internal utility,
getTopLevelMediaType, and traces the consequence toresolveFullMediaType. - The proposed fix directly modifies the inspected validation logic.
- No real application or production incident is described.
If you find bugs through an agent audit, please share the prompts you used instead. Please see our updated guidelines at https://github.com/vercel/ai/issues/17243. If you have any questions, comment on #24118.