8

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?

2

1 Answer 1

7

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.

9
  • 2
    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.
    – Sean Worle
    Aug 11, 2021 at 18:12
  • 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.
    – sleske
    Aug 16, 2021 at 5:58
  • 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.
    – Sean Worle
    Aug 17, 2021 at 14:00
  • 1
    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).
    – Minok
    Aug 24, 2021 at 20:48
  • 1
    @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.
    – nmtoken
    Mar 16, 2022 at 13:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .