Index: content/browser/child_process_security_policy_impl.cc |
diff --git a/content/browser/child_process_security_policy_impl.cc b/content/browser/child_process_security_policy_impl.cc |
index 28ce45ad809ad34567726a34478ff43627bf5f67..8b2b0808361fbc98a8dfa28c3c99163adefa695f 100644 |
--- a/content/browser/child_process_security_policy_impl.cc |
+++ b/content/browser/child_process_security_policy_impl.cc |
@@ -15,17 +15,21 @@ |
#include "base/memory/ptr_util.h" |
#include "base/metrics/histogram_macros.h" |
#include "base/strings/string_util.h" |
+#include "base/strings/utf_string_conversions.h" |
#include "build/build_config.h" |
#include "content/browser/site_instance_impl.h" |
#include "content/common/site_isolation_policy.h" |
#include "content/public/browser/child_process_data.h" |
#include "content/public/browser/content_browser_client.h" |
#include "content/public/browser/render_process_host.h" |
+#include "content/public/browser/storage_partition.h" |
#include "content/public/common/bindings_policy.h" |
+#include "content/public/common/drop_data.h" |
#include "content/public/common/url_constants.h" |
#include "net/base/filename_util.h" |
#include "net/url_request/url_request.h" |
#include "storage/browser/fileapi/file_permission_policy.h" |
+#include "storage/browser/fileapi/file_system_context.h" |
#include "storage/browser/fileapi/file_system_url.h" |
#include "storage/browser/fileapi/isolated_context.h" |
#include "storage/common/fileapi/file_system_util.h" |
@@ -942,6 +946,85 @@ bool ChildProcessSecurityPolicyImpl::HasSpecificPermissionForOrigin( |
return state->second->CanCommitOrigin(origin); |
} |
+void ChildProcessSecurityPolicyImpl::GrantFileAccessFromDropData( |
+ int child_id, |
+ const storage::FileSystemContext* file_system_context, |
+ DropData* drop_data) { |
+#if defined(OS_CHROMEOS) |
+ // The externalfile:// scheme is used in Chrome OS to open external files in a |
+ // browser tab. |
+ if (drop_data->url.SchemeIs(content::kExternalFileScheme)) |
+ GrantRequestURL(child_id, drop_data->url); |
+#endif |
+ |
+ // The filenames vector represents a capability to access the given files. |
+ storage::IsolatedContext::FileInfoSet files; |
+ for (auto& filename : drop_data->filenames) { |
+ // Make sure we have the same display_name as the one we register. |
+ if (filename.display_name.empty()) { |
+ std::string name; |
+ files.AddPath(filename.path, &name); |
+ filename.display_name = base::FilePath::FromUTF8Unsafe(name); |
ncarter (slow)
2017/04/24 18:54:46
Mutating the |drop_data| seems like an unusual con
Łukasz Anforowicz
2017/04/24 21:30:23
Good point. I should have raised this as a concer
|
+ } else { |
+ files.AddPathWithName(filename.path, |
+ filename.display_name.AsUTF8Unsafe()); |
+ } |
+ // A dragged file may wind up as the value of an input element, or it |
+ // may be used as the target of a navigation instead. We don't know |
+ // which will happen at this point, so generously grant both access |
+ // and request permissions to the specific file to cover both cases. |
+ // We do not give it the permission to request all file:// URLs. |
+ GrantRequestSpecificFileURL(child_id, |
+ net::FilePathToFileURL(filename.path)); |
+ |
+ // If the renderer already has permission to read these paths, we don't need |
+ // to re-grant them. This prevents problems with DnD for files in the CrOS |
+ // file manager--the file manager already had read/write access to those |
+ // directories, but dragging a file would cause the read/write access to be |
+ // overwritten with read-only access, making them impossible to delete or |
+ // rename until the renderer was killed. |
+ if (!CanReadFile(child_id, filename.path)) |
+ GrantReadFile(child_id, filename.path); |
+ } |
+ |
+ storage::IsolatedContext* isolated_context = |
+ storage::IsolatedContext::GetInstance(); |
+ DCHECK(isolated_context); |
+ |
+ if (!files.fileset().empty()) { |
+ std::string filesystem_id = |
+ isolated_context->RegisterDraggedFileSystem(files); |
ncarter (slow)
2017/04/24 18:54:46
I am not convinced that CPSP is the right place fo
Łukasz Anforowicz
2017/04/24 21:30:23
Thanks for pointing this out - I haven't considere
ncarter (slow)
2017/04/24 22:01:51
I agree with the feeling that it ought to be both
|
+ if (!filesystem_id.empty()) { |
+ // Grant the permission iff the ID is valid. |
+ GrantReadFileSystem(child_id, filesystem_id); |
+ } |
+ drop_data->filesystem_id = base::UTF8ToUTF16(filesystem_id); |
+ } |
+ |
+ for (auto& file_system_file : drop_data->file_system_files) { |
+ storage::FileSystemURL file_system_url = |
+ file_system_context->CrackURL(file_system_file.url); |
+ |
+ std::string register_name; |
+ std::string filesystem_id = isolated_context->RegisterFileSystemForPath( |
+ file_system_url.type(), file_system_url.filesystem_id(), |
+ file_system_url.path(), ®ister_name); |
+ |
+ if (!filesystem_id.empty()) { |
+ // Grant the permission iff the ID is valid. |
+ GrantReadFileSystem(child_id, filesystem_id); |
+ } |
+ |
+ // Note: We are using the origin URL provided by the sender here. It may be |
+ // different from the receiver's. |
+ file_system_file.url = |
+ GURL(storage::GetIsolatedFileSystemRootURIString( |
+ file_system_url.origin(), filesystem_id, std::string()) |
+ .append(register_name)); |
+ file_system_file.filesystem_id = filesystem_id; |
+ } |
+} |
+ |
void ChildProcessSecurityPolicyImpl::LockToOrigin(int child_id, |
const GURL& gurl) { |
// "gurl" can be currently empty in some cases, such as file://blah. |