Skip to content

fix(parser): keep img srcset when src is a data: URI - #1908

Merged
Mzack9999 merged 1 commit into
projectdiscovery:devfrom
protonnegativo:fix/img-data-src-srcset
Oct 26, 2026
Merged

Mzack9999 merged 1 commit into
projectdiscovery:devfrom
protonnegativo:fix/img-data-src-srcset

Conversation

@protonnegativo

@protonnegativo protonnegativo commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1909

Related discussion: #1907

Proposed changes

bodyImgTagParser returned from the per-element callback when src was a data: URI. The srcset check comes after it, so the srcset of that <img> was never parsed. A data: placeholder in src with the real images in srcset is a common lazy-loading pattern.

The parser now skips only the data: src and keeps reading the element. data: URLs are still not emitted.

Proof

New subtest TestBodyParsers/img/srcset-with-data-src fails on dev (no URLs returned) and passes with the change. go test ./pkg/engine/parser/ passes, go vet and gofmt are clean.

Local repro:

<img src="data:image/gif;base64,R0lGODlhAQABAAAAACw=" srcset="/resize.php?w=320 1x, /resize-2x.php?w=640 2x" alt="">
$ katana -u http://127.0.0.1:19500/ -d 2 -duc -silent
# before
http://127.0.0.1:19500/
# after
http://127.0.0.1:19500/
http://127.0.0.1:19500/resize.php?w=320
http://127.0.0.1:19500/resize-2x.php?w=640

Checklist

  • Pull request is created against the dev branch
  • All checks passed (lint, unit/integration/regression tests etc.) with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Summary by CodeRabbit

  • Bug Fixes
    • Improved image parsing when an image uses an embedded data URI as its primary source. Responsive image candidates are now still processed, so their resolved URLs can be discovered instead of being skipped along with the primary source. This helps pages that combine embedded images with alternate image sources display or process those alternatives as expected.

bodyImgTagParser returned from the element callback when src was a data:
URI, so a srcset on the same <img> was never read. A data: placeholder in
src with the real images in srcset is a common lazy-loading pattern.

Skip only the data: src and keep parsing the element.
@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 15174012-3bc5-4769-98b4-0c0db127cadd
Commits

Reviewing files that changed from the base of the PR and between 5f44366 and 118874d.

Files selected for processing: 2
  • pkg/engine/parser/parser.go
  • pkg/engine/parser/parser_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

The image parser now skips creating a navigation request for a data-URI src and continues processing the image’s srcset. A test checks that both srcset candidate URLs are returned.

Changes

Image parser

Layer / File(s) Summary
Data-URI source and srcset processing
pkg/engine/parser/parser.go, pkg/engine/parser/parser_test.go
The parser skips a data-URI src without returning early. The test checks that both srcset candidate URLs are returned.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: mzack9999

Merge Risk: Minimal · up to 11887

The change preserves srcset processing without introducing an emitted navigation request for mixed-case data URIs.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main parser fix: preserving image srcset processing when src uses a data: URI.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks the image stream,
A data source slips by unseen.
Two srcset paths hop into view,
The parser follows both paths through.
The rabbit nods, then bounds away.

Comment @coderabbitai help to get the list of available commands.

@Mzack9999
Mzack9999 merged commit 7092260 into projectdiscovery:dev Oct 26, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

img srcset is skipped when src is a data URI

2 participants