Skip to content

Commit 8d1df08

Browse files
authored
Fix icon redirect not working on desktop (dani-garcia#5536)
* Fix icon redirect not working on desktop We also need to exclude the header in case we do an external_icon call. Fixes dani-garcia#5535 Signed-off-by: BlackDex <[email protected]> * Add informational comments to the icon_external function Signed-off-by: BlackDex <[email protected]> * Fix spelling/grammar Signed-off-by: BlackDex <[email protected]> --------- Signed-off-by: BlackDex <[email protected]>
1 parent 3b6bccd commit 8d1df08

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/api/icons.rs

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ static CLIENT: Lazy<Client> = Lazy::new(|| {
6363
// Build Regex only once since this takes a lot of time.
6464
static ICON_SIZE_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?x)(\d+)\D*(\d+)").unwrap());
6565

66+
// The function name `icon_external` is checked in the `on_response` function in `AppHeaders`
67+
// It is used to prevent sending a specific header which breaks icon downloads.
68+
// If this function needs to be renamed, also adjust the code in `util.rs`
6669
#[get("/<domain>/icon.png")]
6770
fn icon_external(domain: &str) -> Option<Redirect> {
6871
if !is_valid_domain(domain) {

src/util.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,17 @@ impl Fairing for AppHeaders {
5656
res.set_raw_header("X-Content-Type-Options", "nosniff");
5757
res.set_raw_header("X-Robots-Tag", "noindex, nofollow");
5858

59-
if !res.headers().get_one("Content-Type").is_some_and(|v| v.starts_with("image/")) {
60-
res.set_raw_header("Cross-Origin-Resource-Policy", "same-origin");
61-
}
62-
6359
// Obsolete in modern browsers, unsafe (XS-Leak), and largely replaced by CSP
6460
res.set_raw_header("X-XSS-Protection", "0");
6561

62+
// The `Cross-Origin-Resource-Policy` header should not be set on images or on the `icon_external` route.
63+
// Otherwise some clients, like the Bitwarden Desktop, will fail to download the icons
64+
if !(res.headers().get_one("Content-Type").is_some_and(|v| v.starts_with("image/"))
65+
|| req.route().is_some_and(|v| v.name.as_deref() == Some("icon_external")))
66+
{
67+
res.set_raw_header("Cross-Origin-Resource-Policy", "same-origin");
68+
}
69+
6670
// Do not send the Content-Security-Policy (CSP) Header and X-Frame-Options for the *-connector.html files.
6771
// This can cause issues when some MFA requests needs to open a popup or page within the clients like WebAuthn, or Duo.
6872
// This is the same behavior as upstream Bitwarden.

0 commit comments

Comments
 (0)