Skip to content

Commit

Permalink
reading local file resources is still allowed if the enclosing docume…
Browse files Browse the repository at this point in the history
…nt itself was loaded from file (#786)
  • Loading branch information
rbri committed May 14, 2024
1 parent 107dbe3 commit e104703
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
Make HtmlElement.type() allow full-width space (\u3000), six-per-em space (\u2006) and tab (\t) characters.
</action>
<action type="update" dev="Lai Quang Duong">
Prevent iframes from loading local resource for security reason.
Prevent iframes from loading local resource for security reason (reading local file resources is still allowed
if the enclosing document itself was loaded from file).
</action>
<action type="update" dev="Lai Quang Duong">
Prevent XMLHttpRequest from loading local resource for security reason.
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/htmlunit/html/BaseFrameElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,15 @@ private void loadInnerPageIfPossible(final String src) throws FailingHttpStatusC
return;
}

final URL pageUrl = page.getUrl();

// accessing to local resource is forbidden for security reason
if ("file".equals(url.getProtocol())) {
if (!"file".equals(pageUrl.getProtocol()) && "file".equals(url.getProtocol())) {
notifyIncorrectness("Not allowed to load local resource: " + source);
return;
}

final Charset pageCharset = page.getCharset();
final URL pageUrl = page.getUrl();
final WebRequest request = new WebRequest(url, pageCharset, pageUrl);

if (isAlreadyLoadedByAncestor(url, request.getCharset())) {
Expand Down

0 comments on commit e104703

Please sign in to comment.