Skip to content

Commit 05d3cf9

Browse files
authored
urlencode user queries when forwarding to bang location to prevent open redirect vulnerabilities (#239)
1 parent 3945651 commit 05d3cf9

File tree

7 files changed

+40
-14
lines changed

7 files changed

+40
-14
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ whatlang = { version = "0.16.0", features = ["serde"] }
186186
xxhash-rust = { version = "0.8.10", features = ["xxh3", "const_xxh3"] }
187187
zipf = "7.0.0"
188188
zstd = { version = "0.13", features = ["experimental"] }
189+
urlencoding = "2.1.3"
189190

190191
[profile.test.package]
191192
flate2.opt-level = 3

assets/licenses.html

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ <h1>Third Party Licenses</h1>
4545
<h2>Overview of licenses:</h2>
4646
<ul class="licenses-overview">
4747
<li><a href="#Apache-2.0">Apache License 2.0</a> (411)</li>
48-
<li><a href="#MIT">MIT License</a> (190)</li>
48+
<li><a href="#MIT">MIT License</a> (191)</li>
4949
<li><a href="#AGPL-3.0">GNU Affero General Public License v3.0</a> (9)</li>
5050
<li><a href="#BSD-3-Clause">BSD 3-Clause &quot;New&quot; or &quot;Revised&quot; License</a> (9)</li>
5151
<li><a href="#MPL-2.0">Mozilla Public License 2.0</a> (8)</li>
@@ -14111,6 +14111,34 @@ <h4>Used by:</h4>
1411114111
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1411214112
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1411314113
SOFTWARE.
14114+
</pre>
14115+
</li>
14116+
<li class="license">
14117+
<h3 id="MIT">MIT License</h3>
14118+
<h4>Used by:</h4>
14119+
<ul class="license-used-by">
14120+
<li><a href=" https://github.com/kornelski/rust_urlencoding ">urlencoding 2.1.3</a></li>
14121+
</ul>
14122+
<pre class="license-text">© 2016 Bertram Truong
14123+
© 2021 Kornel Lesiński
14124+
14125+
Permission is hereby granted, free of charge, to any person obtaining a copy
14126+
of this software and associated documentation files (the &quot;Software&quot;), to deal
14127+
in the Software without restriction, including without limitation the rights
14128+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14129+
copies of the Software, and to permit persons to whom the Software is
14130+
furnished to do so, subject to the following conditions:
14131+
14132+
The above copyright notice and this permission notice shall be included in
14133+
all copies or substantial portions of the Software.
14134+
14135+
THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14136+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14137+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14138+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14139+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
14140+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
14141+
THE SOFTWARE.
1411414142
</pre>
1411514143
</li>
1411614144
<li class="license">

crates/core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ utoipa.workspace = true
116116
uuid.workspace = true
117117
whatlang.workspace = true
118118
zimba = { path = "../zimba" }
119+
urlencoding.workspace = true
119120

120121
[target.'cfg(not(target_env = "msvc"))'.dependencies]
121122
tikv-jemallocator.workspace = true

crates/core/src/bangs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl Bangs {
169169
)
170170
.collect::<String>();
171171

172-
let query = crate::urlencode(query.as_str());
172+
let query = urlencoding::encode(query.as_str()).into_owned();
173173
let url = bang.url.replace("{{{s}}}", query.as_str());
174174

175175
return Url::parse(url.as_str())

crates/core/src/lib.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -396,17 +396,6 @@ pub fn mv<P1: AsRef<std::path::Path>, P2: AsRef<std::path::Path>>(
396396
Ok(())
397397
}
398398

399-
pub fn urlencode(s: &str) -> String {
400-
const FRAGMENT: &percent_encoding::AsciiSet = &percent_encoding::CONTROLS
401-
.add(b' ')
402-
.add(b'"')
403-
.add(b'<')
404-
.add(b'>')
405-
.add(b'`');
406-
407-
percent_encoding::utf8_percent_encode(s, FRAGMENT).to_string()
408-
}
409-
410399
#[cfg(test)]
411400
mod tests {
412401
use super::*;

crates/core/src/searcher/api/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ where
304304
.collect();
305305

306306
let mut query = query.clone();
307-
query.query = q;
307+
query.query = urlencoding::encode(&q).into_owned();
308308

309309
let res = self.search_websites(&query).await?;
310310

0 commit comments

Comments
 (0)