Skip to content

Fix data URL validation in summarizeDataUrl - #1230

Open
pavankumar-vh wants to merge 1 commit into
CodebuffAI:mainfrom
pavankumar-vh:fix/cache-debug-data-url-validation
Open

Fix data URL validation in summarizeDataUrl#1230
pavankumar-vh wants to merge 1 commit into
CodebuffAI:mainfrom
pavankumar-vh:fix/cache-debug-data-url-validation

Conversation

@pavankumar-vh

Copy link
Copy Markdown

Overview

Fix a potential bug in the summarizeDataUrl function in common/src/util/cache-debug.ts.

Bug Description

The summarizeDataUrl function assumed the value started with data: (5 characters) and sliced from index 5 to extract the media type. If the value didn't start with data:, this would return incorrect results.

Fix

Added a check to ensure the header starts with data: before slicing, returning 'unknown' as the media type if it doesn't.

Testing

No existing tests for this function, but the fix prevents incorrect behavior with malformed data URLs.

Files Changed

  • common/src/util/cache-debug.ts - Added data URL validation

Scope

This change only touches common/ which is an approved contribution area per the Contributing Guide.

The summarizeDataUrl function assumed the value started with 'data:' (5 chars)
and sliced from index 5 to extract the media type. If the value didn't start
with 'data:', this would return incorrect results.

Added a check to ensure the header starts with 'data:' before slicing,
returning 'unknown' as the media type if it doesn't.
@codebuff-team

Copy link
Copy Markdown
Contributor

Thanks for the contribution. The change itself is safe and in-scope (common/), but I'd like to see evidence this guard actually fixes an observable bug. Looking at cache-debug.ts, summarizeDataUrl is presumably only invoked after the caller has already confirmed value.startsWith('data:'), so header should always begin with data: by the time this function runs. If that's the case, this change is a no-op defensive check rather than a real bug fix.

If you found a path where summarizeDataUrl can be called with non-data: values (e.g. from a different caller than the current one), please point to it in the PR description - that would make this a genuine fix. Otherwise, consider adding a unit test that exercises the malformed-header case to demonstrate the previous behavior was actually wrong (what did header.slice(5) return before, and was it actually incorrect/misleading, or just cosmetically odd?).

As it stands this is low-risk but not clearly necessary — happy to reconsider with a concrete before/after example or a test.

@codebuff-team codebuff-team added bot:triaged Classified by the community triage bot pr:needs-work Right idea, not mergeable as written labels Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:triaged Classified by the community triage bot pr:needs-work Right idea, not mergeable as written

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants