Skip to content

Commit acbdc66

Browse files
committed
Implement COOP and COEP
1 parent 34a9d6b commit acbdc66

5 files changed

Lines changed: 32 additions & 0 deletions

File tree

benches/header_map/basic.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,8 @@ const STD: &'static [HeaderName] = &[
547547
CONTENT_SECURITY_POLICY_REPORT_ONLY,
548548
CONTENT_TYPE,
549549
COOKIE,
550+
CROSS_ORIGIN_EMBEDDER_POLICY,
551+
CROSS_ORIGIN_OPENER_POLICY,
550552
DNT,
551553
DATE,
552554
ETAG,

src/header/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ pub use self::name::{
112112
CONTENT_SECURITY_POLICY_REPORT_ONLY,
113113
CONTENT_TYPE,
114114
COOKIE,
115+
CROSS_ORIGIN_EMBEDDER_POLICY,
116+
CROSS_ORIGIN_OPENER_POLICY,
115117
DNT,
116118
DATE,
117119
ETAG,

src/header/name.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,30 @@ standard_headers! {
464464
/// the browser are set to block them, for example.
465465
(Cookie, COOKIE, b"cookie");
466466

467+
/// Allows a server to declare an embedder policy for a given document.
468+
///
469+
/// The HTTP `Cross-Origin-Embedder-Policy` (COEP) response header prevents
470+
/// a document from loading any cross-origin resources that don't
471+
/// explicitly grant the document permission (using CORP or CORS).
472+
(CrossOriginEmbedderPolicy, CROSS_ORIGIN_EMBEDDER_POLICY, b"cross-origin-embedder-policy");
473+
474+
/// Prevents other domains from opening/controlling a window.
475+
///
476+
/// The HTTP `Cross-Origin-Opener-Policy` (COOP) response header allows you
477+
/// to ensure a top-level document does not share a browsing context group
478+
/// with cross-origin documents.
479+
///
480+
/// COOP will process-isolate your document and potential attackers can't
481+
/// access your global object if they were to open it in a popup,
482+
/// preventing a set of cross-origin attacks dubbed XS-Leaks.
483+
///
484+
/// If a cross-origin document with COOP is opened in a new window, the
485+
/// opening document will not have a reference to it, and the
486+
/// `window.opener` property of the new window will be `null`. This allows
487+
/// you to have more control over references to a window than
488+
/// `rel=noopener`, which only affects outgoing navigations.
489+
(CrossOriginOpenerPolicy, CROSS_ORIGIN_OPENER_POLICY, b"cross-origin-opener-policy");
490+
467491
/// Indicates the client's tracking preference.
468492
///
469493
/// This header lets users indicate whether they would prefer privacy rather

tests/header_map.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ const STD: &'static [HeaderName] = &[
357357
CONTENT_SECURITY_POLICY_REPORT_ONLY,
358358
CONTENT_TYPE,
359359
COOKIE,
360+
CROSS_ORIGIN_EMBEDDER_POLICY,
361+
CROSS_ORIGIN_OPENER_POLICY,
360362
DNT,
361363
DATE,
362364
ETAG,

tests/header_map_fuzz.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ fn gen_header_name(g: &mut StdRng) -> HeaderName {
292292
header::CONTENT_SECURITY_POLICY_REPORT_ONLY,
293293
header::CONTENT_TYPE,
294294
header::COOKIE,
295+
header::CROSS_ORIGIN_EMBEDDER_POLICY,
296+
header::CROSS_ORIGIN_OPENER_POLICY,
295297
header::DNT,
296298
header::DATE,
297299
header::ETAG,

0 commit comments

Comments
 (0)