Skip to content

Commit

Permalink
Cherry-pick 272448.2@safari-7618-branch (18fd76f). https://bugs.webki…
Browse files Browse the repository at this point in the history
…t.org/show_bug.cgi?id=266703

    Ensure Filesystem root path is not empty
    https://bugs.webkit.org/show_bug.cgi?id=266703
    rdar://119813501

    Reviewed by Chris Dumez.

    When the root path is empty, then the file's name can define an arbitrary
    filesystem path. This change ensures that the path is non-empty, therefore the
    virtual filesystem must be defined under a directory that the user selected.

    * LayoutTests/http/tests/security/file-system-access-via-dataTransfer-expected.txt: Added.
    * LayoutTests/http/tests/security/file-system-access-via-dataTransfer.html: Added.
    * Source/WebCore/Modules/entriesapi/DOMFileSystem.cpp:
    (WebCore::DOMFileSystem::getEntry):
    (WebCore::DOMFileSystem::getFile):

    Canonical link: https://commits.webkit.org/272448.2@safari-7618-branch

Canonical link: https://commits.webkit.org/274313.49@webkitglib/2.44
  • Loading branch information
sysrqb authored and aperezdc committed Mar 11, 2024
1 parent e5cffbd commit cf0035a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Test that accessing local file system metadata is not allowed

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS Should not receive file
PASS successfullyParsed is true

TEST COMPLETE

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<html>
<head>
<script src="/js-test-resources/js-test.js"></script>
<body>

<script>
description("Test that accessing local file system metadata is not allowed");

function runTest() {
if (!window.internals) {
alert("This test depends on Internals");
return;
}

window.jsTestIsAsync = true;

let path = location.pathname.split("/");
let targetFileName = internals.createTemporaryFile(`${path[path.length - 1]}`, "");

let input = document.createElement("input");
input.type = "file";

let file = new File([], targetFileName, {"type":"text/plain"});

dataTransfer = new DataTransfer();
dataTransfer.items.add(file)
input.files = dataTransfer.files;

var functionOnSuccess = function (file)
{
testFailed("Should not receive file");
finishJSTest()
}

var functionOnError = function (value)
{
testPassed("Should not receive file");
finishJSTest()
}

input.webkitEntries.forEach((entry) => {
entry.file(functionOnSuccess, functionOnError)
});
}

runTest();

</script>
</body>
</html>
5 changes: 5 additions & 0 deletions Source/WebCore/Modules/entriesapi/DOMFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ void DOMFileSystem::getEntry(ScriptExecutionContext& context, FileSystemDirector
return;
}

if (m_rootPath.isEmpty())
return completionCallback(Exception { ExceptionCode::NotFoundError, "Path does not exist"_s });

m_workQueue->dispatch([protectedThis = Ref { *this }, context = Ref { context }, fullPath = crossThreadCopy(WTFMove(fullPath)), resolvedVirtualPath = crossThreadCopy(WTFMove(resolvedVirtualPath)), completionCallback = WTFMove(completionCallback)]() mutable {
auto entryType = fileTypeIgnoringHiddenFiles(fullPath);
callOnMainThread([protectedThis = WTFMove(protectedThis), context = WTFMove(context), resolvedVirtualPath = crossThreadCopy(WTFMove(resolvedVirtualPath)), entryType, completionCallback = WTFMove(completionCallback)]() mutable {
Expand All @@ -327,6 +330,8 @@ void DOMFileSystem::getEntry(ScriptExecutionContext& context, FileSystemDirector

void DOMFileSystem::getFile(ScriptExecutionContext& context, FileSystemFileEntry& fileEntry, GetFileCallback&& completionCallback)
{
if (m_rootPath.isEmpty())
return completionCallback(Exception { ExceptionCode::NotFoundError, "Path does not exist"_s });
auto virtualPath = fileEntry.virtualPath();
auto fullPath = evaluatePath(virtualPath);
m_workQueue->dispatch([fullPath = crossThreadCopy(WTFMove(fullPath)), virtualPath = crossThreadCopy(WTFMove(virtualPath)), context = Ref { context }, completionCallback = WTFMove(completionCallback)]() mutable {
Expand Down

0 comments on commit cf0035a

Please sign in to comment.