Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(411)

Side by Side Diff: Source/platform/weborigin/SecurityOrigin.cpp

Issue 299253003: [webcrypto] Only allow crypto.subtle.* to be used from "secure origins". (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add more tests Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 20 matching lines...) Expand all
31 31
32 #include "platform/weborigin/KURL.h" 32 #include "platform/weborigin/KURL.h"
33 #include "platform/weborigin/KnownPorts.h" 33 #include "platform/weborigin/KnownPorts.h"
34 #include "platform/weborigin/SchemeRegistry.h" 34 #include "platform/weborigin/SchemeRegistry.h"
35 #include "platform/weborigin/SecurityOriginCache.h" 35 #include "platform/weborigin/SecurityOriginCache.h"
36 #include "platform/weborigin/SecurityPolicy.h" 36 #include "platform/weborigin/SecurityPolicy.h"
37 #include "wtf/HexNumber.h" 37 #include "wtf/HexNumber.h"
38 #include "wtf/MainThread.h" 38 #include "wtf/MainThread.h"
39 #include "wtf/StdLibExtras.h" 39 #include "wtf/StdLibExtras.h"
40 #include "wtf/text/StringBuilder.h" 40 #include "wtf/text/StringBuilder.h"
41 #include <url/url_canon_ip.h>
abarth-chromium 2014/06/10 17:09:11 #include "url/url_canon_ip.h" You should probably
eroman 2014/06/10 18:47:26 Done.
41 42
42 namespace WebCore { 43 namespace WebCore {
43 44
44 const int InvalidPort = 0; 45 const int InvalidPort = 0;
45 const int MaxAllowedPort = 65535; 46 const int MaxAllowedPort = 65535;
46 47
47 static SecurityOriginCache* s_originCache = 0; 48 static SecurityOriginCache* s_originCache = 0;
48 49
49 static bool schemeRequiresAuthority(const KURL& url) 50 static bool schemeRequiresAuthority(const KURL& url)
50 { 51 {
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 369
369 if (SchemeRegistry::shouldTreatURLSchemeAsDisplayIsolated(protocol)) 370 if (SchemeRegistry::shouldTreatURLSchemeAsDisplayIsolated(protocol))
370 return m_protocol == protocol || SecurityPolicy::isAccessToURLWhiteListe d(this, url); 371 return m_protocol == protocol || SecurityPolicy::isAccessToURLWhiteListe d(this, url);
371 372
372 if (SchemeRegistry::shouldTreatURLSchemeAsLocal(protocol)) 373 if (SchemeRegistry::shouldTreatURLSchemeAsLocal(protocol))
373 return canLoadLocalResources() || SecurityPolicy::isAccessToURLWhiteList ed(this, url); 374 return canLoadLocalResources() || SecurityPolicy::isAccessToURLWhiteList ed(this, url);
374 375
375 return true; 376 return true;
376 } 377 }
377 378
379 bool SecurityOrigin::canAccessFeatureRequiringSecureOrigin() const
380 {
381 ASSERT(m_protocol != "data");
382 return isLocal() || isLocalhost() || SchemeRegistry::shouldTreatURLSchemeAsS ecure(m_protocol);
abarth-chromium 2014/06/10 17:09:11 We should move isLocalhost() to the end because it
eroman 2014/06/10 18:47:26 Good point! Done. Similarly, I moved the secure s
383 }
384
378 SecurityOrigin::Policy SecurityOrigin::canShowNotifications() const 385 SecurityOrigin::Policy SecurityOrigin::canShowNotifications() const
379 { 386 {
380 if (m_universalAccess) 387 if (m_universalAccess)
381 return AlwaysAllow; 388 return AlwaysAllow;
382 if (isUnique()) 389 if (isUnique())
383 return AlwaysDeny; 390 return AlwaysDeny;
384 return Ask; 391 return Ask;
385 } 392 }
386 393
387 void SecurityOrigin::grantLoadLocalResources() 394 void SecurityOrigin::grantLoadLocalResources()
(...skipping 14 matching lines...) Expand all
402 { 409 {
403 ASSERT(isLocal()); 410 ASSERT(isLocal());
404 m_enforceFilePathSeparation = true; 411 m_enforceFilePathSeparation = true;
405 } 412 }
406 413
407 bool SecurityOrigin::isLocal() const 414 bool SecurityOrigin::isLocal() const
408 { 415 {
409 return SchemeRegistry::shouldTreatURLSchemeAsLocal(m_protocol); 416 return SchemeRegistry::shouldTreatURLSchemeAsLocal(m_protocol);
410 } 417 }
411 418
419 bool SecurityOrigin::isLocalhost() const
420 {
421 if (m_host == "localhost")
422 return true;
423
424 if (m_host == "[::1]")
425 return true;
426
427 // Test if m_host matches 127.0.0.1/8
428 ASSERT(m_host.containsOnlyASCII());
429 CString hostAscii = m_host.ascii();
430 Vector<uint8, 4> ipNumber;
431 ipNumber.resize(4);
432
433 int numComponents;
434 url::Component hostComponent(0, hostAscii.length());
435 url::CanonHostInfo::Family family = url::IPv4AddressToNumber(
436 hostAscii.data(), hostComponent, &(ipNumber)[0], &numComponents);
437 if (family != url::CanonHostInfo::IPV4)
438 return false;
439 return ipNumber[0] == 127;
440 }
441
412 String SecurityOrigin::toString() const 442 String SecurityOrigin::toString() const
413 { 443 {
414 if (isUnique()) 444 if (isUnique())
415 return "null"; 445 return "null";
416 if (m_protocol == "file" && m_enforceFilePathSeparation) 446 if (m_protocol == "file" && m_enforceFilePathSeparation)
417 return "null"; 447 return "null";
418 return toRawString(); 448 return toRawString();
419 } 449 }
420 450
421 AtomicString SecurityOrigin::toAtomicString() const 451 AtomicString SecurityOrigin::toAtomicString() const
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 } 521 }
492 522
493 const String& SecurityOrigin::urlWithUniqueSecurityOrigin() 523 const String& SecurityOrigin::urlWithUniqueSecurityOrigin()
494 { 524 {
495 ASSERT(isMainThread()); 525 ASSERT(isMainThread());
496 DEFINE_STATIC_LOCAL(const String, uniqueSecurityOriginURL, ("data:,")); 526 DEFINE_STATIC_LOCAL(const String, uniqueSecurityOriginURL, ("data:,"));
497 return uniqueSecurityOriginURL; 527 return uniqueSecurityOriginURL;
498 } 528 }
499 529
500 } // namespace WebCore 530 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/platform/weborigin/SecurityOrigin.h ('k') | Source/platform/weborigin/SecurityOriginTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698