Skip to content

Commit 011aa01

Browse files
RickeyWardgezihuzi
authored andcommitted
feat(http): add dangerous settings / disable ssl verification - issue tauri-apps#518 (tauri-apps#2204)
1 parent 8a4ecb7 commit 011aa01

File tree

6 files changed

+62
-2
lines changed

6 files changed

+62
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"http": minor
3+
"http-js": minor
4+
---
5+
6+
Add `dangerous-settings` feature flag and new JS `danger` option to disable tls hostname/certificate validation.

plugins/http/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,4 @@ charset = ["reqwest/charset"]
7373
macos-system-configuration = ["reqwest/macos-system-configuration"]
7474
unsafe-headers = []
7575
tracing = ["dep:tracing"]
76+
dangerous-settings = []

plugins/http/api-iife.js

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

plugins/http/guest-js/index.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,26 @@ export interface ClientOptions {
8484
* Configuration of a proxy that a Client should pass requests to.
8585
*/
8686
proxy?: Proxy
87+
/**
88+
* Configuration for dangerous settings on the client such as disabling SSL verification.
89+
*/
90+
danger?: DangerousSettings
91+
}
92+
93+
/**
94+
* Configuration for dangerous settings on the client such as disabling SSL verification.
95+
*
96+
* @since 2.3.0
97+
*/
98+
export interface DangerousSettings {
99+
/**
100+
* Disables SSL verification.
101+
*/
102+
acceptInvalidCerts?: boolean
103+
/**
104+
* Disables hostname verification.
105+
*/
106+
acceptInvalidHostnames?: boolean
87107
}
88108

89109
const ERROR_REQUEST_CANCELLED = 'Request canceled'
@@ -115,12 +135,14 @@ export async function fetch(
115135
const maxRedirections = init?.maxRedirections
116136
const connectTimeout = init?.connectTimeout
117137
const proxy = init?.proxy
138+
const danger = init?.danger
118139

119140
// Remove these fields before creating the request
120141
if (init) {
121142
delete init.maxRedirections
122143
delete init.connectTimeout
123144
delete init.proxy
145+
delete init.danger
124146
}
125147

126148
const headers = init?.headers
@@ -172,7 +194,8 @@ export async function fetch(
172194
data,
173195
maxRedirections,
174196
connectTimeout,
175-
proxy
197+
proxy,
198+
danger
176199
}
177200
})
178201

plugins/http/src/commands.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ pub struct FetchResponse {
7575
rid: ResourceId,
7676
}
7777

78+
#[derive(Debug, Deserialize)]
79+
#[serde(rename_all = "camelCase")]
80+
#[allow(dead_code)] //feature flags shoudln't affect api
81+
pub struct DangerousSettings {
82+
accept_invalid_certs: bool,
83+
accept_invalid_hostnames: bool,
84+
}
85+
7886
#[derive(Debug, Deserialize)]
7987
#[serde(rename_all = "camelCase")]
8088
pub struct ClientConfig {
@@ -85,6 +93,7 @@ pub struct ClientConfig {
8593
connect_timeout: Option<u64>,
8694
max_redirections: Option<usize>,
8795
proxy: Option<Proxy>,
96+
danger: Option<DangerousSettings>,
8897
}
8998

9099
#[derive(Debug, Deserialize)]
@@ -181,6 +190,7 @@ pub async fn fetch<R: Runtime>(
181190
connect_timeout,
182191
max_redirections,
183192
proxy,
193+
danger,
184194
} = client_config;
185195

186196
let scheme = url.scheme();
@@ -220,6 +230,24 @@ pub async fn fetch<R: Runtime>(
220230
{
221231
let mut builder = reqwest::ClientBuilder::new();
222232

233+
if let Some(danger_config) = danger {
234+
#[cfg(not(feature = "dangerous-settings"))]
235+
{
236+
#[cfg(debug_assertions)]
237+
{
238+
eprintln!("[\x1b[33mWARNING\x1b[0m] using dangerous settings requires `dangerous-settings` feature flag in your Cargo.toml");
239+
}
240+
let _ = danger_config;
241+
return Err(Error::DangerousSettings);
242+
}
243+
#[cfg(feature = "dangerous-settings")]
244+
{
245+
builder = builder
246+
.danger_accept_invalid_certs(danger_config.accept_invalid_certs)
247+
.danger_accept_invalid_hostnames(danger_config.accept_invalid_hostnames)
248+
}
249+
}
250+
223251
if let Some(timeout) = connect_timeout {
224252
builder = builder.connect_timeout(Duration::from_millis(timeout));
225253
}

plugins/http/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ pub enum Error {
4141
Tauri(#[from] tauri::Error),
4242
#[error(transparent)]
4343
Utf8(#[from] std::string::FromUtf8Error),
44+
#[error("dangerous settings used but are not enabled")]
45+
DangerousSettings,
4446
}
4547

4648
impl Serialize for Error {

0 commit comments

Comments
 (0)