Skip to content

fix(core/data-include): Validate response.ok before injecting data-include content - #5389

Merged
marcoscaceres merged 3 commits into
mainfrom
copilot/fix-404-error-in-data-include
Aug 11, 2026
Merged

fix(core/data-include): Validate response.ok before injecting data-include content#5389
marcoscaceres merged 3 commits into
mainfrom
copilot/fix-404-error-in-data-include

Conversation

Copilot AI commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

data-include read response.text() without checking the fetch response status, so a server error page (e.g. a 404 HTML page) could be silently injected into the document body.

Changes

  • src/core/data-include.js: check response.ok right after fetch(url); if not OK, throw before reading the body so no error-page content ever reaches processResponse.
  • Error message: now includes the HTTP status code and status text, plus a troubleshooting hint, surfaced through the existing showError path.
  • Tests: added a not-found-include fixture (tests/spec/core/includer.html) pointing at a nonexistent file, and a spec asserting the failed include produces a core/data-include error containing the status code and leaves the target element empty.
const response = await fetch(url);
if (!response.ok) {
  throw new Error(
    `Fetching \`${url}\` failed with status code ${response.status} (${response.statusText}).`
  );
}
const text = await response.text();

Copilot AI changed the title [WIP] Fix data-include to handle 404 errors properly Validate response.ok before injecting data-include content Aug 11, 2026
Copilot AI requested a review from marcoscaceres August 11, 2026 13:08
@marcoscaceres
marcoscaceres marked this pull request as ready for review August 11, 2026 13:33
@marcoscaceres marcoscaceres changed the title Validate response.ok before injecting data-include content fix(core/data-include): Validate response.ok before injecting data-include content Aug 11, 2026
@marcoscaceres
marcoscaceres merged commit 751f56d into main Aug 11, 2026
9 of 10 checks passed
@marcoscaceres
marcoscaceres deleted the copilot/fix-404-error-in-data-include branch August 11, 2026 14:18
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.

data-include might insert the 404 error page

2 participants