How do I instruct Firefox to allow me to open file:/// URLs on a localhost-server http:// webpage?

6,694

Shamelessly stealing from my answer on StackOverflow:

Links to local files on pages that were retrieved via HTTP(S) are deliberately disabled in Mozilla/Firefox, because they can be a security risk, and have been used in attacks in the past.

You can override this behaviour, however.

Short version:

You need to configure Firefox' Security Policy to allow links to local files. This can be done either using the configuration file policies.json (all platforms), or by using Windows Group Policies (only on MS Window).

In both cases, the setting to change is LocalFileLinks - it contains a list of domains where links to local files are allowed.

Example policies.json:

{
  "policies": {
    "LocalFileLinks": ["http://example.org/",
                       "http://example.edu/"]
  }
}

For details, see this article in MozillaZine, and How to access the local filesystem from a webpage in Firefox on Mozilla Support.

Share:
6,694

Related videos on Youtube

David
Author by

David

Updated on September 18, 2022

Comments

  • David
    David almost 2 years

    I have made a WWW control panel running on http://127.0.0.1/.

    When I open it in Firefox and click a link such as:

    <a href="file:///C:/Users/John%20Doe/Documents/test/log.txt">test</>
    

    Nothing happens. Why doesn't it open the file:/// URL, whether it be in Firefox or with my OS-specified (or Firefox-specified) .txt handler application? It used to work when I was using an RSS client instead of my browser for this (it opened Notepad++ and went to the right file).

    Why doesn't Firefox do anything whatsoever? It doesn't even dump any kind of error message in the "Console" of Firefox, which usually happens whenever there is some issue like this.

    Nope. Nothing. It just doesn't care about the URL.

    In spite of the lack of any error, I suspect it has something to do with not getting to mix file:/// URLs in a http://-served webpage or something. If so, is there perhaps some nice "meta tag" or something I can use to instruct Firefox that yes, I want this particular page to be allowed to open file:/// URLs?

    • dillonbrannick
      dillonbrannick over 4 years
      Not sure if you just mistyped it for the question, but you're missing the /a at the end.
    • sleske
      sleske over 4 years
      This has already been asked (and answered) on StackOverflow: Cross-browser link to file on local system.
  • Sean Worle
    Sean Worle almost 3 years
    Is this no longer supported in the current version? I tried this and nothing changed. Pasting a "file:///..." URL into the address bar just hangs and does nothing.
  • sleske
    sleske almost 3 years
    I haven't checked the "LocalFileLinks" configuration recently, but file:/// URLs definitely still work. However, they need to reference a file/directory that actually exists. For example, try file:///C:/Users on Windows.
  • Sean Worle
    Sean Worle almost 3 years
    So, if you create a valid HTML file in, say, C:\testing, and then paste the following URL into Firefox: file:///C:/testing/mytest.htm , you can get it to display as expected? Because I am not able to get that to work, no matter what I do.
  • sleske
    sleske almost 3 years
    @SeanWorle: Yes, that works for me. If it does not work for you, consider asking a new question, with more details.
  • Minok
    Minok almost 3 years
    I just don't see the security problem that Mozilla sees and suspect its an overly broad hammer to fix a tiny problem, that effectively cripples many local/machine documentation systems. Loading a c:/somedir/file.html works fine, but the links inside that html that point to c:/some-other-dir/another-file.ctx don't work - nothing gets processed or handed off to the OS (windows in this case) for its appropriately assigned application to take over opening the file. Where is that security risk that caused this lockdown? (I'm refering to a file already on my system from a file on my system).
  • sleske
    sleske almost 3 years
    @Minok: Links from one local HTML file to another should work - I just tested. If it fails for you, consider asking a new question.
  • nmtoken
    nmtoken over 2 years
    The question isn't about one html file to another, it's about linking to a non-HTML file ( a log file)
  • sleske
    sleske over 2 years
    @nmtoken: True, but the answer should apply independent of file type. If you have a problem specific to non-HTML files, consider asking a new question.
  • nmtoken
    nmtoken over 2 years
    @Sleske if the answer applies to all files that's great. The OP asked originally about non HTML, they commented on your answer not working for non-HTML, and you replied about HTML. I can't see why a new question needs to be asked for non-HTML as that was the original question.