Skip to content

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

Downloads: Akamai's refusal of programs is a bot check, so MDM tries again as a browser connects (#771) (#776)

Ahmed Nefzaouid8147ab28c1b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3271f5ad..e2b99f6c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,6 +24,7 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
### Fixed
+- Sites behind Akamai that let only browsers through (a 403 "Access Denied" page for MDM, the file for a browser, such as HPE's documentation PDFs) now download: MDM takes Akamai's refusal for the bot check it is and tries again the way a browser connects, as it does for Cloudflare's ([#771](https://github.com/anefzaoui/misterdownloadmanager/issues/771)).
- Crash and freeze reports keep the log lines that explain them: 25 of the file-type icons carried no-op styles (`marker:none`, `mask:none` and the like) that MDM's SVG reader warned about each time they were drawn, 1,385 lines for one look at them all, and those warnings filled the end of the log a report includes ([#767](https://github.com/anefzaoui/misterdownloadmanager/issues/767)). The icons look the same.
- The download windows no longer freeze while a drive is slow to answer (a hard disk waking up, a USB drive, a network or mapped folder). **Download File Info** asked the disk whether its file's name was taken (to number it `(1)`) on the window's own thread, and so did **Show in folder**, **Open folder**, **Open** and the drag handle in **Download complete**, the question to create a missing folder, the look for files a torrent would write into, and the progress window's check of a folder for **Rename**; the window waited for the disk, 8 seconds and more in the reports. They now ask beside the window. Meanwhile Save As shows the name as it is, without `(1)`, and takes the numbered one when the answer comes; a download started before then is numbered as it starts, so nothing is overwritten ([#743](https://github.com/anefzaoui/misterdownloadmanager/issues/743), [#751](https://github.com/anefzaoui/misterdownloadmanager/issues/751)).
- **Sizes for a stream's qualities:** HLS qualities showed no size; each is now estimated from its bitrate and the video's length, in the Download video window and in the download list.
diff --git a/ROADMAP.md b/ROADMAP.md
index 43bf12eb..6d813ac1 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -503,6 +503,8 @@ Bug fixes from the first days of 0.5.0, a Safari extension, and more file types.
These ship in the next version.
+- ✅ Sites behind Akamai's bot check (a 403 page for MDM, the file for a browser) download, through the
+ browser-like connection ([#771](https://github.com/anefzaoui/misterdownloadmanager/issues/771))
- ✅ Crash and freeze reports no longer have their log's end filled with warnings about the
file-type icons ([#767](https://github.com/anefzaoui/misterdownloadmanager/issues/767))
- ✅ Videos and image galleries keep to the speed limits (for one file, their own, and all
diff --git a/crates/engine/src/download.rs b/crates/engine/src/download.rs
index 36de43aa..87884b56 100644
--- a/crates/engine/src/download.rs
+++ b/crates/engine/src/download.rs
@@ -3487,11 +3487,58 @@ fn header_str(h: &HeaderMap, name: header::HeaderName) -> Option<&str> {
h.get(name).and_then(|v| v.to_str().ok())
}
-/// A site's bot check turning the request away (#376), as Cloudflare marks it.
+/// A site's bot check turning the request away: Cloudflare's, which marks it
+/// (`cf-mitigated: challenge`, #376), or Akamai's, whose edge answers a connection it takes for a
+/// program's with its own 403 page ("Access Denied", served by `AkamaiGHost`, #771), where a
+/// browser gets the file. The site's own 403 behind Akamai comes from its servers, not the edge's
+/// page, and stays a plain refusal.
pub(crate) fn is_bot_check(status: StatusCode, h: &HeaderMap) -> bool {
status == StatusCode::FORBIDDEN
- && h.get("cf-mitigated")
+ && (h
+ .get("cf-mitigated")
.is_some_and(|v| v.as_bytes().eq_ignore_ascii_case(b"challenge"))
+ || (header_str(h, header::SERVER)
+ .is_some_and(|s| s.trim().eq_ignore_ascii_case("AkamaiGHost"))
+ && is_web_page(h)))
+}
+
+#[cfg(test)]
+mod bot_check_tests {
+ use super::*;
+
+ fn headers(pairs: &[(&'static str, &'static str)]) -> HeaderMap {
+ let mut h = HeaderMap::new();
+ for (k, v) in pairs {
+ h.insert(*k, header::HeaderValue::from_static(v));
+ }
+ h
+ }
+
+ /// Cloudflare's challenge and Akamai's edge refusal (#771) are bot checks; a 403 from the site
+ /// itself, or Akamai's edge sending something other than its page, is not.
+ #[test]
+ fn bot_checks_are_cloudflares_challenge_and_akamais_edge_page() {
+ let forbidden = StatusCode::FORBIDDEN;
+ assert!(is_bot_check(
+ forbidden,
+ &headers(&[("cf-mitigated", "challenge")])
+ ));
+ let akamai = headers(&[("server", "AkamaiGHost"), ("content-type", "text/html")]);
+ assert!(is_bot_check(forbidden, &akamai));
+ assert!(!is_bot_check(StatusCode::NOT_FOUND, &akamai));
+ assert!(!is_bot_check(
+ forbidden,
+ &headers(&[
+ ("server", "AkamaiGHost"),
+ ("content-type", "application/pdf")
+ ])
+ ));
+ assert!(!is_bot_check(
+ forbidden,
+ &headers(&[("server", "nginx"), ("content-type", "text/html")])
+ ));
+ assert!(!is_bot_check(forbidden, &HeaderMap::new()));
+ }
}
pub(crate) fn is_web_page(h: &HeaderMap) -> bool {