summaryrefslogtreecommitdiff
path: root/ext/websocket/lib.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2022-09-27 22:36:33 +0200
committerGitHub <noreply@github.com>2022-09-27 22:36:33 +0200
commit212b7dd6da487c070229b6348ec7907b4fecbcf9 (patch)
tree3eb743f90e8b293182a830722eb4ff26bec72039 /ext/websocket/lib.rs
parenta344368603063bcb281e743f3810ca1e4e46e85d (diff)
feat: Add requesting API name to permission prompt (#15936)
Co-authored-by: Leo Kettmeir <crowlkats@toaxl.com>
Diffstat (limited to 'ext/websocket/lib.rs')
-rw-r--r--ext/websocket/lib.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/ext/websocket/lib.rs b/ext/websocket/lib.rs
index fad217585..e8ada74a2 100644
--- a/ext/websocket/lib.rs
+++ b/ext/websocket/lib.rs
@@ -61,7 +61,11 @@ pub struct WsRootStore(pub Option<RootCertStore>);
pub struct WsUserAgent(pub String);
pub trait WebSocketPermissions {
- fn check_net_url(&mut self, _url: &url::Url) -> Result<(), AnyError>;
+ fn check_net_url(
+ &mut self,
+ _url: &url::Url,
+ _api_name: &str,
+ ) -> Result<(), AnyError>;
}
/// `UnsafelyIgnoreCertificateErrors` is a wrapper struct so it can be placed inside `GothamState`;
@@ -211,6 +215,7 @@ impl Resource for WsCancelResource {
#[op]
pub fn op_ws_check_permission_and_cancel_handle<WP>(
state: &mut OpState,
+ api_name: String,
url: String,
cancel_handle: bool,
) -> Result<Option<ResourceId>, AnyError>
@@ -219,7 +224,7 @@ where
{
state
.borrow_mut::<WP>()
- .check_net_url(&url::Url::parse(&url)?)?;
+ .check_net_url(&url::Url::parse(&url)?, &api_name)?;
if cancel_handle {
let rid = state
@@ -242,6 +247,7 @@ pub struct CreateResponse {
#[op]
pub async fn op_ws_create<WP>(
state: Rc<RefCell<OpState>>,
+ api_name: String,
url: String,
protocols: String,
cancel_handle: Option<ResourceId>,
@@ -253,7 +259,7 @@ where
{
let mut s = state.borrow_mut();
s.borrow_mut::<WP>()
- .check_net_url(&url::Url::parse(&url)?)
+ .check_net_url(&url::Url::parse(&url)?, &api_name)
.expect(
"Permission check should have been done in op_ws_check_permission",
);