OLD | NEW |
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 16 matching lines...) Expand all Loading... |
27 */ | 27 */ |
28 | 28 |
29 #include "config.h" | 29 #include "config.h" |
30 #include "platform/weborigin/SecurityOrigin.h" | 30 #include "platform/weborigin/SecurityOrigin.h" |
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 "url/url_canon_ip.h" |
37 #include "wtf/HexNumber.h" | 38 #include "wtf/HexNumber.h" |
38 #include "wtf/MainThread.h" | 39 #include "wtf/MainThread.h" |
39 #include "wtf/StdLibExtras.h" | 40 #include "wtf/StdLibExtras.h" |
40 #include "wtf/text/StringBuilder.h" | 41 #include "wtf/text/StringBuilder.h" |
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 |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 SchemeRegistry::shouldTreatURLSchemeAsSecure(m_protocol) || isLocal()
|| isLocalhost(); |
| 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 Loading... |
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 Loading... |
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 |
OLD | NEW |