Skip to content

Commit d4743a7

Browse files
committed
Universal access for Child process security policy
Support for nwjs/nw.js#927
1 parent 3778f3e commit d4743a7

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

content/browser/child_process_security_policy_impl.cc

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ class ChildProcessSecurityPolicyImpl::SecurityState {
7575
public:
7676
SecurityState()
7777
: enabled_bindings_(0),
78-
can_read_raw_cookies_(false) { }
78+
can_read_raw_cookies_(false),
79+
universal_access_(false) { }
7980

8081
~SecurityState() {
8182
scheme_policy_.clear();
@@ -90,6 +91,10 @@ class ChildProcessSecurityPolicyImpl::SecurityState {
9091
file_permissions_.size());
9192
}
9293

94+
void GrantUniversalAccess() {
95+
universal_access_ = true;
96+
}
97+
9398
// Grant permission to request URLs with the specified scheme.
9499
void GrantScheme(const std::string& scheme) {
95100
scheme_policy_[scheme] = true;
@@ -152,6 +157,9 @@ class ChildProcessSecurityPolicyImpl::SecurityState {
152157

153158
// Determine whether permission has been granted to request |url|.
154159
bool CanRequestURL(const GURL& url) {
160+
if (universal_access_)
161+
return true;
162+
155163
// Having permission to a scheme implies permssion to all of its URLs.
156164
SchemeMap::const_iterator judgment(scheme_policy_.find(url.scheme()));
157165
if (judgment != scheme_policy_.end())
@@ -170,6 +178,9 @@ class ChildProcessSecurityPolicyImpl::SecurityState {
170178

171179
// Determine if the certain permissions have been granted to a file.
172180
bool HasPermissionsForFile(const base::FilePath& file, int permissions) {
181+
if (universal_access_)
182+
return true;
183+
173184
if (!permissions || file.empty() || !file.IsAbsolute())
174185
return false;
175186
base::FilePath current_path = file.StripTrailingSeparators();
@@ -194,6 +205,9 @@ class ChildProcessSecurityPolicyImpl::SecurityState {
194205
}
195206

196207
bool CanLoadPage(const GURL& gurl) {
208+
if (universal_access_)
209+
return true;
210+
197211
if (origin_lock_.is_empty())
198212
return true;
199213

@@ -205,6 +219,9 @@ class ChildProcessSecurityPolicyImpl::SecurityState {
205219
}
206220

207221
bool CanAccessCookiesForOrigin(const GURL& gurl) {
222+
if (universal_access_)
223+
return true;
224+
208225
if (origin_lock_.is_empty())
209226
return true;
210227
// TODO(creis): We must pass the valid browser_context to convert hosted
@@ -215,6 +232,9 @@ class ChildProcessSecurityPolicyImpl::SecurityState {
215232
}
216233

217234
bool CanSendCookiesForOrigin(const GURL& gurl) {
235+
if (universal_access_)
236+
return true;
237+
218238
// We only block cross-site cookies on network requests if the
219239
// --enable-strict-site-isolation flag is passed. This is expected to break
220240
// compatibility with many sites. The similar --site-per-process flag only
@@ -242,6 +262,9 @@ class ChildProcessSecurityPolicyImpl::SecurityState {
242262
}
243263

244264
bool can_read_raw_cookies() const {
265+
if (universal_access_)
266+
return true;
267+
245268
return can_read_raw_cookies_;
246269
}
247270

@@ -275,6 +298,8 @@ class ChildProcessSecurityPolicyImpl::SecurityState {
275298
// The set of isolated filesystems the child process is permitted to access.
276299
FileSystemMap filesystem_permissions_;
277300

301+
bool universal_access_;
302+
278303
DISALLOW_COPY_AND_ASSIGN(SecurityState);
279304
};
280305

@@ -366,6 +391,15 @@ bool ChildProcessSecurityPolicyImpl::IsPseudoScheme(
366391
return (pseudo_schemes_.find(scheme) != pseudo_schemes_.end());
367392
}
368393

394+
void ChildProcessSecurityPolicyImpl::GrantUniversalAccess(
395+
int child_id) {
396+
base::AutoLock lock(lock_);
397+
SecurityStateMap::iterator state = security_state_.find(child_id);
398+
if (state == security_state_.end())
399+
return;
400+
state->second->GrantUniversalAccess();
401+
}
402+
369403
void ChildProcessSecurityPolicyImpl::GrantRequestURL(
370404
int child_id, const GURL& url) {
371405

content/browser/child_process_security_policy_impl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class CONTENT_EXPORT ChildProcessSecurityPolicyImpl
4242
// ChildProcessSecurityPolicy implementation.
4343
virtual void RegisterWebSafeScheme(const std::string& scheme) OVERRIDE;
4444
virtual bool IsWebSafeScheme(const std::string& scheme) OVERRIDE;
45+
virtual void GrantUniversalAccess(int child_id) OVERRIDE;
4546
virtual void GrantReadFile(int child_id, const base::FilePath& file) OVERRIDE;
4647
virtual void GrantCreateReadWriteFile(int child_id,
4748
const base::FilePath& file) OVERRIDE;

content/public/browser/child_process_security_policy.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ class ChildProcessSecurityPolicy {
4040
// Returns true iff |scheme| has been registered as a web-safe scheme.
4141
virtual bool IsWebSafeScheme(const std::string& scheme) = 0;
4242

43-
// This permission grants only read access to a file.
43+
// node-webkit: grant all to node.js frames
44+
virtual void GrantUniversalAccess(int child_id) = 0;
45+
4446
// Whenever the user picks a file from a <input type="file"> element, the
4547
// browser should call this function to grant the child process the capability
4648
// to upload the file to the web. Grants FILE_PERMISSION_READ_ONLY.

0 commit comments

Comments
 (0)