Skip to content

Commit 2229946

Browse files
committed
Propagate destination through load_data
This way, we don't always set the destination to Document (which is as the spec is written today). Instead, we set it it in the load_data, depending on which context we load it from. Doing so allows us to set the `Destination::IFrame` for navigations in iframes, enabling all frame-related CSP checks. While we currently block iframes when `frame-src` or `child-src` is set, their respective tests don't pass yet. That's because we don't yet handle the cases where we fire the correct `load` event. Part of servo#4577 Signed-off-by: Tim van der Lippe <[email protected]>
1 parent f7b1673 commit 2229946

File tree

11 files changed

+36
-17
lines changed

11 files changed

+36
-17
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,6 @@ codegen-units = 1
245245
# [patch."https://github.com/servo/<repository>"]
246246
# <crate> = { path = "/path/to/local/checkout" }
247247
#
248-
# [patch."https://github.com/servo/rust-content-security-policy"]
249-
# content-security-policy = { path = "../rust-content-security-policy/" }
248+
[patch."https://github.com/servo/rust-content-security-policy"]
249+
content-security-policy = { path = "../rust-content-security-policy/" }
250250
# content-security-policy = { git = "https://github.com/timvdlippe/rust-content-security-policy/", branch = "fix-report-checks", features = ["serde"] }

components/constellation/constellation.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ use keyboard_types::{Key, KeyState, KeyboardEvent, Modifiers};
145145
use log::{debug, error, info, trace, warn};
146146
use media::WindowGLContext;
147147
use net_traits::pub_domains::reg_host;
148-
use net_traits::request::Referrer;
148+
use net_traits::request::{Destination, Referrer};
149149
use net_traits::storage_thread::{StorageThreadMsg, StorageType};
150150
use net_traits::{self, IpcSend, ReferrerPolicy, ResourceThreads};
151151
use profile_traits::{mem, time};
@@ -1369,6 +1369,7 @@ where
13691369
None,
13701370
None,
13711371
false,
1372+
Destination::Document,
13721373
);
13731374
let ctx_id = BrowsingContextId::from(webview_id);
13741375
let pipeline_id = match self.browsing_contexts.get(&ctx_id) {
@@ -3120,6 +3121,7 @@ where
31203121
None,
31213122
None,
31223123
false,
3124+
Destination::Document,
31233125
);
31243126
let sandbox = IFrameSandboxState::IFrameUnsandboxed;
31253127
let is_private = false;
@@ -4730,6 +4732,7 @@ where
47304732
None,
47314733
None,
47324734
false,
4735+
Destination::Document,
47334736
);
47344737
self.load_url_for_webdriver(
47354738
webview_id,

components/script/dom/htmlformelement.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use http::Method;
1414
use js::rust::HandleObject;
1515
use mime::{self, Mime};
1616
use net_traits::http_percent_encode;
17-
use net_traits::request::Referrer;
17+
use net_traits::request::{Destination, Referrer};
1818
use servo_rand::random;
1919
use style::attr::AttrValue;
2020
use style::str::split_html_space_chars;
@@ -868,6 +868,7 @@ impl HTMLFormElement {
868868
Some(target_window.as_global_scope().is_secure_context()),
869869
Some(target_document.insecure_requests_policy()),
870870
target_document.has_trustworthy_ancestor_origin(),
871+
Destination::Document,
871872
);
872873

873874
// Step 22

components/script/dom/htmliframeelement.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use embedder_traits::ViewportDetails;
1616
use html5ever::{LocalName, Prefix, local_name, ns};
1717
use js::rust::HandleObject;
1818
use net_traits::ReferrerPolicy;
19+
use net_traits::request::Destination;
1920
use profile_traits::ipc as ProfiledIpc;
2021
use script_traits::{NewLayoutInfo, UpdatePipelineIdReason};
2122
use servo_url::ServoUrl;
@@ -281,6 +282,7 @@ impl HTMLIFrameElement {
281282
Some(window.as_global_scope().is_secure_context()),
282283
Some(document.insecure_requests_policy()),
283284
document.has_trustworthy_ancestor_or_current_origin(),
285+
Destination::IFrame,
284286
);
285287
load_data.policy_container = Some(window.as_global_scope().policy_container());
286288
let element = self.upcast::<Element>();
@@ -374,6 +376,7 @@ impl HTMLIFrameElement {
374376
Some(window.as_global_scope().is_secure_context()),
375377
Some(document.insecure_requests_policy()),
376378
document.has_trustworthy_ancestor_or_current_origin(),
379+
Destination::IFrame,
377380
);
378381

379382
let pipeline_id = self.pipeline_id();
@@ -382,9 +385,7 @@ impl HTMLIFrameElement {
382385
let is_about_blank =
383386
pipeline_id.is_some() && pipeline_id == self.about_blank_pipeline_id.get();
384387

385-
if is_about_blank {
386-
load_data.policy_container = Some(window.as_global_scope().policy_container());
387-
}
388+
load_data.policy_container = Some(window.as_global_scope().policy_container());
388389

389390
let history_handling = if is_about_blank {
390391
NavigationHistoryBehavior::Replace
@@ -424,6 +425,7 @@ impl HTMLIFrameElement {
424425
Some(window.as_global_scope().is_secure_context()),
425426
Some(document.insecure_requests_policy()),
426427
document.has_trustworthy_ancestor_or_current_origin(),
428+
Destination::IFrame,
427429
);
428430
load_data.policy_container = Some(window.as_global_scope().policy_container());
429431
let browsing_context_id = BrowsingContextId::new();

components/script/dom/location.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use constellation_traits::{LoadData, LoadOrigin, NavigationHistoryBehavior};
66
use dom_struct::dom_struct;
7-
use net_traits::request::Referrer;
7+
use net_traits::request::{Destination, Referrer};
88
use servo_url::{MutableOrigin, ServoUrl};
99

1010
use crate::dom::bindings::codegen::Bindings::LocationBinding::LocationMethods;
@@ -127,6 +127,7 @@ impl Location {
127127
None, // Top navigation doesn't inherit secure context
128128
Some(source_document.insecure_requests_policy()),
129129
source_document.has_trustworthy_ancestor_origin(),
130+
Destination::Document,
130131
);
131132
self.window
132133
.load_url(history_handling, reload_triggered, load_data, can_gc);

components/script/dom/windowproxy.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use js::jsval::{NullValue, PrivateValue, UndefinedValue};
3232
use js::rust::wrappers::{JS_TransplantObject, NewWindowProxy, SetWindowProxy};
3333
use js::rust::{Handle, MutableHandle, MutableHandleValue, get_object_class};
3434
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
35-
use net_traits::request::Referrer;
35+
use net_traits::request::{Destination, Referrer};
3636
use script_traits::NewLayoutInfo;
3737
use serde::{Deserialize, Serialize};
3838
use servo_url::{ImmutableOrigin, ServoUrl};
@@ -309,6 +309,7 @@ impl WindowProxy {
309309
None, // Doesn't inherit secure context
310310
None,
311311
false,
312+
Destination::Document,
312313
);
313314
let load_info = AuxiliaryWebViewCreationRequest {
314315
load_data: load_data.clone(),
@@ -525,6 +526,7 @@ impl WindowProxy {
525526
Some(secure),
526527
Some(target_document.insecure_requests_policy()),
527528
has_trustworthy_ancestor_origin,
529+
Destination::Document,
528530
);
529531
let history_handling = if new {
530532
NavigationHistoryBehavior::Replace

components/script/links.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use constellation_traits::{LoadData, LoadOrigin, NavigationHistoryBehavior};
88
use html5ever::{local_name, ns};
99
use malloc_size_of::malloc_size_of_is_0;
10-
use net_traits::request::Referrer;
10+
use net_traits::request::{Destination, Referrer};
1111
use style::str::HTML_SPACE_CHARACTERS;
1212

1313
use crate::dom::bindings::codegen::Bindings::AttrBinding::Attr_Binding::AttrMethods;
@@ -441,6 +441,7 @@ pub(crate) fn follow_hyperlink(
441441
Some(secure),
442442
Some(document.insecure_requests_policy()),
443443
document.has_trustworthy_ancestor_origin(),
444+
Destination::Document,
444445
);
445446
let target = Trusted::new(target_window);
446447
let task = task!(navigate_follow_hyperlink: move || {

components/script/navigation.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ use std::cell::Cell;
1111
use base::cross_process_instant::CrossProcessInstant;
1212
use base::id::{BrowsingContextId, PipelineId, WebViewId};
1313
use constellation_traits::LoadData;
14-
use content_security_policy::Destination;
1514
use crossbeam_channel::Sender;
1615
use embedder_traits::ViewportDetails;
1716
use http::header;
17+
use net_traits::policy_container::PolicyContainer;
1818
use net_traits::request::{
1919
CredentialsMode, InsecureRequestsPolicy, RedirectMode, RequestBuilder, RequestMode,
2020
};
@@ -202,12 +202,18 @@ impl InProgressLoad {
202202
self.load_data.referrer.clone(),
203203
)
204204
.method(self.load_data.method.clone())
205-
.destination(Destination::Document)
205+
.destination(self.load_data.destination.clone())
206206
.mode(RequestMode::Navigate)
207207
.credentials_mode(CredentialsMode::Include)
208208
.use_url_credentials(true)
209209
.pipeline_id(Some(id))
210210
.referrer_policy(self.load_data.referrer_policy)
211+
.policy_container(
212+
self.load_data
213+
.policy_container
214+
.clone()
215+
.unwrap_or(PolicyContainer::default()),
216+
)
211217
.insecure_requests_policy(
212218
self.load_data
213219
.inherited_insecure_requests_policy

components/shared/constellation/from_script_message.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use http::{HeaderMap, Method};
2323
use ipc_channel::Error as IpcError;
2424
use ipc_channel::ipc::{IpcReceiver, IpcSender};
2525
use net_traits::policy_container::PolicyContainer;
26-
use net_traits::request::{InsecureRequestsPolicy, Referrer, RequestBody};
26+
use net_traits::request::{Destination, InsecureRequestsPolicy, Referrer, RequestBody};
2727
use net_traits::storage_thread::StorageType;
2828
use net_traits::{CoreResourceMsg, ReferrerPolicy, ResourceThreads};
2929
use profile_traits::mem::MemoryReportResult;
@@ -111,6 +111,8 @@ pub struct LoadData {
111111
pub has_trustworthy_ancestor_origin: bool,
112112
/// Servo internal: if crash details are present, trigger a crash error page with these details.
113113
pub crash: Option<String>,
114+
/// Destination, used for CSP checks
115+
pub destination: Destination,
114116
}
115117

116118
/// The result of evaluating a javascript scheme url.
@@ -135,6 +137,7 @@ impl LoadData {
135137
inherited_secure_context: Option<bool>,
136138
inherited_insecure_requests_policy: Option<InsecureRequestsPolicy>,
137139
has_trustworthy_ancestor_origin: bool,
140+
destination: Destination,
138141
) -> LoadData {
139142
LoadData {
140143
load_origin,
@@ -152,6 +155,7 @@ impl LoadData {
152155
crash: None,
153156
inherited_insecure_requests_policy,
154157
has_trustworthy_ancestor_origin,
158+
destination,
155159
}
156160
}
157161
}

tests/wpt/tests/content-security-policy/frame-src/frame-src-blocked.sub.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818
}, false);
1919

2020
function alert_assert(msg) {
21-
t_alert.step(function() {
21+
t_log.step(function() {
2222
if (msg.match(/^FAIL/i)) {
2323
assert_unreached(msg);
24-
t_alert.done();
24+
t_log.done();
2525
}
2626
for (var i = 0; i < expected_alerts.length; i++) {
2727
if (expected_alerts[i] == msg) {
2828
assert_equals(expected_alerts[i], msg);
2929
expected_alerts.splice(i, 1);
3030
if (expected_alerts.length == 0) {
31-
t_alert.done();
31+
t_log.done();
3232
}
3333
return;
3434
}

0 commit comments

Comments
 (0)