Skip to content

misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux

Debrid sign-in by code: only the service's own page is opened (#635)

Ahmed Nefzaouie7237345530e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index eb3edfab..f23c3ff8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,10 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
- Videos a site sends in pieces (HLS and DASH streams, as many sites other than YouTube do) download several pieces at once, as many as **Options → Connection** gives a file (8 by default): against a test server that slows each connection, 4 at once took under a third of the time, 8 under a fifth. With a speed limit on, they still come one at a time, so the limit holds; a video in one file, as most of YouTube's are, is unchanged. The command line's `video-get` and `playlist-get` take `-c` for it ([#531](https://github.com/anefzaoui/misterdownloadmanager/issues/531)).
- Linux and macOS: a yt-dlp installed by the system (a package manager, Homebrew) is found and used when MDM has none of its own; **Helpers** can still switch to MDM's own copy, kept up to date ([#452](https://github.com/anefzaoui/misterdownloadmanager/issues/452)).
+### Changed
+
+- Debrid accounts: signing in by code opens the page only when it is the service's own site, over https.
+
### Fixed
- Raising a speed limit, or turning it off, applies at once: to a download's own limit (its progress window's **Speed Limiter** tab), the limit for one file and the limit for all downloads together. A connection already waiting its turn under the old limit sat out the wait the old limit gave it, many seconds at a low limit, before the new speed showed; it now counts what is left at the new limit, and ends its wait as soon as there is no limit ([#621](https://github.com/anefzaoui/misterdownloadmanager/issues/621)).
diff --git a/ROADMAP.md b/ROADMAP.md
index e55c48e1..86df3543 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -501,6 +501,7 @@ Bug fixes from the first days of 0.5.0, a Safari extension, and more file types.
These ship in the next version.
+- ✅ Debrid accounts: signing in by code opens only the service's own page
- ✅ A speed limit raised or turned off applies at once, to the connections already waiting
under the old one too ([#621](https://github.com/anefzaoui/misterdownloadmanager/issues/621))
- ✅ The build and release workflows: each job gets only the permissions it needs, and every
diff --git a/crates/debrid/src/lib.rs b/crates/debrid/src/lib.rs
index 41c728c1..4ac091bd 100644
--- a/crates/debrid/src/lib.rs
+++ b/crates/debrid/src/lib.rs
@@ -777,6 +777,7 @@ pub mod signin {
match service {
ServiceKind::RealDebrid => {
let c = realdebrid::device_code(http).await?;
+ own_page(service, &c.verification_url)?;
Ok(Code {
shown: c.user_code.clone(),
page: c.verification_url.clone(),
@@ -787,6 +788,7 @@ pub mod signin {
}
ServiceKind::AllDebrid => {
let p = alldebrid::pin(http).await?;
+ own_page(service, &p.user_url)?;
Ok(Code {
shown: p.pin.clone(),
page: p.user_url.clone(),
@@ -802,6 +804,30 @@ pub mod signin {
}
}
+ /// The page MDM opens in the browser for the user to type the code at comes from the
+ /// service's answer: it is opened only on the service's own site, over https. Anything else
+ /// is a service that isn't answering as it should.
+ fn own_page(service: ServiceKind, page: &str) -> Result<(), Fault> {
+ let site = match service {
+ ServiceKind::RealDebrid => "real-debrid.com",
+ ServiceKind::AllDebrid => "alldebrid.com",
+ ServiceKind::Premiumize => "premiumize.me",
+ };
+ let ok = url::Url::parse(page).is_ok_and(|u| {
+ u.scheme() == "https"
+ && u.username().is_empty()
+ && u.password().is_none()
+ && u.port().is_none()
+ && u.host_str()
+ .is_some_and(|h| h == site || h.ends_with(&format!(".{site}")))
+ });
+ if ok {
+ Ok(())
+ } else {
+ Err(ServiceFault::ServiceDown.into())
+ }
+ }
+
/// Step 2, every `interval` seconds until `expires_in`: the credential once allowed.
pub async fn poll(http: &Http, code: &Code) -> Result<Option<Credential>, Fault> {
match &code.inner {
@@ -822,6 +848,35 @@ pub mod signin {
.map(|token| Credential::Token { token })),
}
}
+
+ #[cfg(test)]
+ mod page_tests {
+ use super::{ServiceKind, own_page};
+
+ #[test]
+ fn only_the_services_own_site_over_https() {
+ let rd = ServiceKind::RealDebrid;
+ let ad = ServiceKind::AllDebrid;
+ assert!(own_page(rd, "https://real-debrid.com/device").is_ok());
+ assert!(own_page(rd, "https://www.real-debrid.com/device").is_ok());
+ assert!(own_page(ad, "https://alldebrid.com/pin/?pin=ABCD").is_ok());
+ for bad in [
+ "http://real-debrid.com/device",
+ "https://real-debrid.com.example.net/device",
+ "https://notreal-debrid.com/device",
+ "https://example.com/real-debrid.com",
+ "https://[email protected]/device",
+ "https://real-debrid.com:8443/device",
+ "file:///C:/Windows/system32/calc.exe",
+ "javascript:alert(1)",
+ "real-debrid.com/device",
+ "",
+ ] {
+ assert!(own_page(rd, bad).is_err(), "{bad}");
+ }
+ assert!(own_page(ad, "https://real-debrid.com/device").is_err());
+ }
+ }
}
#[cfg(test)]