OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/child_process_security_policy_impl.h" | 5 #include "content/browser/child_process_security_policy_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/debug/dump_without_crashing.h" | 11 #include "base/debug/dump_without_crashing.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/strings/utf_string_conversions.h" | |
18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
19 #include "content/browser/site_instance_impl.h" | 20 #include "content/browser/site_instance_impl.h" |
20 #include "content/common/site_isolation_policy.h" | 21 #include "content/common/site_isolation_policy.h" |
21 #include "content/public/browser/child_process_data.h" | 22 #include "content/public/browser/child_process_data.h" |
22 #include "content/public/browser/content_browser_client.h" | 23 #include "content/public/browser/content_browser_client.h" |
23 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
25 #include "content/public/browser/storage_partition.h" | |
24 #include "content/public/common/bindings_policy.h" | 26 #include "content/public/common/bindings_policy.h" |
27 #include "content/public/common/drop_data.h" | |
25 #include "content/public/common/url_constants.h" | 28 #include "content/public/common/url_constants.h" |
26 #include "net/base/filename_util.h" | 29 #include "net/base/filename_util.h" |
27 #include "net/url_request/url_request.h" | 30 #include "net/url_request/url_request.h" |
28 #include "storage/browser/fileapi/file_permission_policy.h" | 31 #include "storage/browser/fileapi/file_permission_policy.h" |
32 #include "storage/browser/fileapi/file_system_context.h" | |
29 #include "storage/browser/fileapi/file_system_url.h" | 33 #include "storage/browser/fileapi/file_system_url.h" |
30 #include "storage/browser/fileapi/isolated_context.h" | 34 #include "storage/browser/fileapi/isolated_context.h" |
31 #include "storage/common/fileapi/file_system_util.h" | 35 #include "storage/common/fileapi/file_system_util.h" |
32 #include "url/gurl.h" | 36 #include "url/gurl.h" |
33 | 37 |
34 namespace content { | 38 namespace content { |
35 | 39 |
36 namespace { | 40 namespace { |
37 | 41 |
38 // Used internally only. These bit positions have no relationship to any | 42 // Used internally only. These bit positions have no relationship to any |
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
935 bool ChildProcessSecurityPolicyImpl::HasSpecificPermissionForOrigin( | 939 bool ChildProcessSecurityPolicyImpl::HasSpecificPermissionForOrigin( |
936 int child_id, | 940 int child_id, |
937 const url::Origin& origin) { | 941 const url::Origin& origin) { |
938 base::AutoLock lock(lock_); | 942 base::AutoLock lock(lock_); |
939 SecurityStateMap::iterator state = security_state_.find(child_id); | 943 SecurityStateMap::iterator state = security_state_.find(child_id); |
940 if (state == security_state_.end()) | 944 if (state == security_state_.end()) |
941 return false; | 945 return false; |
942 return state->second->CanCommitOrigin(origin); | 946 return state->second->CanCommitOrigin(origin); |
943 } | 947 } |
944 | 948 |
949 void ChildProcessSecurityPolicyImpl::GrantFileAccessFromDropData( | |
950 int child_id, | |
951 const storage::FileSystemContext* file_system_context, | |
952 DropData* drop_data) { | |
953 #if defined(OS_CHROMEOS) | |
954 // The externalfile:// scheme is used in Chrome OS to open external files in a | |
955 // browser tab. | |
956 if (drop_data->url.SchemeIs(content::kExternalFileScheme)) | |
957 GrantRequestURL(child_id, drop_data->url); | |
958 #endif | |
959 | |
960 // The filenames vector represents a capability to access the given files. | |
961 storage::IsolatedContext::FileInfoSet files; | |
962 for (auto& filename : drop_data->filenames) { | |
963 // Make sure we have the same display_name as the one we register. | |
964 if (filename.display_name.empty()) { | |
965 std::string name; | |
966 files.AddPath(filename.path, &name); | |
967 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
| |
968 } else { | |
969 files.AddPathWithName(filename.path, | |
970 filename.display_name.AsUTF8Unsafe()); | |
971 } | |
972 // A dragged file may wind up as the value of an input element, or it | |
973 // may be used as the target of a navigation instead. We don't know | |
974 // which will happen at this point, so generously grant both access | |
975 // and request permissions to the specific file to cover both cases. | |
976 // We do not give it the permission to request all file:// URLs. | |
977 GrantRequestSpecificFileURL(child_id, | |
978 net::FilePathToFileURL(filename.path)); | |
979 | |
980 // If the renderer already has permission to read these paths, we don't need | |
981 // to re-grant them. This prevents problems with DnD for files in the CrOS | |
982 // file manager--the file manager already had read/write access to those | |
983 // directories, but dragging a file would cause the read/write access to be | |
984 // overwritten with read-only access, making them impossible to delete or | |
985 // rename until the renderer was killed. | |
986 if (!CanReadFile(child_id, filename.path)) | |
987 GrantReadFile(child_id, filename.path); | |
988 } | |
989 | |
990 storage::IsolatedContext* isolated_context = | |
991 storage::IsolatedContext::GetInstance(); | |
992 DCHECK(isolated_context); | |
993 | |
994 if (!files.fileset().empty()) { | |
995 std::string filesystem_id = | |
996 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
| |
997 if (!filesystem_id.empty()) { | |
998 // Grant the permission iff the ID is valid. | |
999 GrantReadFileSystem(child_id, filesystem_id); | |
1000 } | |
1001 drop_data->filesystem_id = base::UTF8ToUTF16(filesystem_id); | |
1002 } | |
1003 | |
1004 for (auto& file_system_file : drop_data->file_system_files) { | |
1005 storage::FileSystemURL file_system_url = | |
1006 file_system_context->CrackURL(file_system_file.url); | |
1007 | |
1008 std::string register_name; | |
1009 std::string filesystem_id = isolated_context->RegisterFileSystemForPath( | |
1010 file_system_url.type(), file_system_url.filesystem_id(), | |
1011 file_system_url.path(), ®ister_name); | |
1012 | |
1013 if (!filesystem_id.empty()) { | |
1014 // Grant the permission iff the ID is valid. | |
1015 GrantReadFileSystem(child_id, filesystem_id); | |
1016 } | |
1017 | |
1018 // Note: We are using the origin URL provided by the sender here. It may be | |
1019 // different from the receiver's. | |
1020 file_system_file.url = | |
1021 GURL(storage::GetIsolatedFileSystemRootURIString( | |
1022 file_system_url.origin(), filesystem_id, std::string()) | |
1023 .append(register_name)); | |
1024 file_system_file.filesystem_id = filesystem_id; | |
1025 } | |
1026 } | |
1027 | |
945 void ChildProcessSecurityPolicyImpl::LockToOrigin(int child_id, | 1028 void ChildProcessSecurityPolicyImpl::LockToOrigin(int child_id, |
946 const GURL& gurl) { | 1029 const GURL& gurl) { |
947 // "gurl" can be currently empty in some cases, such as file://blah. | 1030 // "gurl" can be currently empty in some cases, such as file://blah. |
948 DCHECK(SiteInstanceImpl::GetSiteForURL(NULL, gurl) == gurl); | 1031 DCHECK(SiteInstanceImpl::GetSiteForURL(NULL, gurl) == gurl); |
949 base::AutoLock lock(lock_); | 1032 base::AutoLock lock(lock_); |
950 SecurityStateMap::iterator state = security_state_.find(child_id); | 1033 SecurityStateMap::iterator state = security_state_.find(child_id); |
951 DCHECK(state != security_state_.end()); | 1034 DCHECK(state != security_state_.end()); |
952 state->second->LockToOrigin(gurl); | 1035 state->second->LockToOrigin(gurl); |
953 } | 1036 } |
954 | 1037 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
987 base::AutoLock lock(lock_); | 1070 base::AutoLock lock(lock_); |
988 | 1071 |
989 SecurityStateMap::iterator state = security_state_.find(child_id); | 1072 SecurityStateMap::iterator state = security_state_.find(child_id); |
990 if (state == security_state_.end()) | 1073 if (state == security_state_.end()) |
991 return false; | 1074 return false; |
992 | 1075 |
993 return state->second->can_send_midi_sysex(); | 1076 return state->second->can_send_midi_sysex(); |
994 } | 1077 } |
995 | 1078 |
996 } // namespace content | 1079 } // namespace content |
OLD | NEW |