36

I have a .asp application where image files (.PDF) are stored in a directory (fed by a copier/scanner). The created file names are stored in a database table. When a query is launched from the web page a link to the file is created. When clicked the image should be displayed. This functionality works 100% in Internet Explorer. No such luck in Firefox (and I have some Firefox users). The created hyperlink looks like this file://Server/Scanner/XYZ.pdf

The Firefox helps suggest the reason is this:

Links to local or network pages do not work. As a security precaution, Firefox forbids sites on the Internet to link to files that are stored in your local computing environment. These files may include files on your computer, mapped network drives, and UNC network paths

None of the suggestions for a workaround seem to work (or I am not understanding the steps to create the image display) Any Suggestions?

endolith
  • 25,479
  • 34
  • 128
  • 192
Joe
  • 791
  • 4
  • 9
  • 11
  • I do not have access to another server at this moment, but on a local share my solution works. – alexandrul Oct 10 '08 at 22:33
  • 2014-04-14 (FF29) https://bugzilla.mozilla.org/show_bug.cgi?id=995943#c5 "we removed the entire capability.policy subsystem. So this isn't going to work anymore." – leo Aug 17 '15 at 07:14

10 Answers10

31

This is the default Firefox behavior designed for security .The assumption is probably that most web sites don't know what and where are you local files (including UNC paths).

This could be turned off in firefox:

  • type "about:config" in the address bar and accept "i'll be careful"
  • find "security.checkloaduri" in older versions or "security.fileuri.strict_origin_policy" in newer versions of firefox and change the value to "false"
  • restart firefox

That should do it for you. You have more information here:

Marko Dumic
  • 9,848
  • 4
  • 29
  • 33
  • Stumbled across this. This isn't working for me on Firefox 3.0.12 for some reason. When I mouse over the path in firebug I see the image thumbnail so I know the path is good. What else could it be? – Scott Feb 27 '11 at 21:54
  • 3
    Are you sure this still works? I followed your instructions in firefox 13.0.1 (linux) and 13.0 (windows). Error Console still gives me a security error: `Content at may not load or link to file:///` @alexandrul's answer works. – Sebastian Jun 29 '12 at 13:03
  • @Sebastian It worked in 2008. I'm not sure about current Firefox. – Marko Dumic Jun 29 '12 at 13:12
14

Firefox >= 68.0.1

I'm able to preview in Firefox both images and PDF files with local file links using the settings mentioned here: https://bugzilla.mozilla.org/show_bug.cgi?id=1303727

I have used links with local file: <a href="file://N:/path/to/file.ext">test</a>

and added in user.js the mentioned settings (with adjusted sites list):

user_pref("capability.policy.policynames", "localfilelinks"); user_pref("capability.policy.localfilelinks.sites", "http://my.intranet"); user_pref("capability.policy.localfilelinks.checkloaduri.enabled", "allAccess");

Also, when setting Firefox to "Always ask" for PDF files, I was able to "Open with" the PDF in Adobe Acrobat Reader DC, which reported the expected local folder when accessing "File -> Properties".


Firefox >= 1.5.x < 20 (ish)

Search for the Firefox profile folder on your hard drive, e.g. (12345678 stands for eight random digits and letters):

  • Windows: "C:\Documents and Settings\Username\Application Data\Mozilla\Firefox\Profiles12345678.default\"
  • Linux: "/home/username/.mozilla/firefox/12345678.default/"
  • OS X: /Username/Library/Application Support/Firefox/Profiles/12345678.default/

In this folder create a text file with the name user.js. Write the following line into that text file:

user_pref("capability.policy.default.checkloaduri.enabled", "allAccess");

Works on my PC (Firefox 3.0.3 and 19.0 beta) with the following references:

  • <img src="file://///server/share/image.png" />
  • <img src="file://\\\server\share\image.png" />
  • <img src="file://d:\image.png" />
  • <img src="file:///d:\image.png" />
  • <img src="file://d:/image.png" />
  • <img src="file:///d:/image.png" />
  • <img src="file://localhost/d:/image.png" />

Also, if you are using the NoScript add-on, check the Advanced \ Trusted \ Allow local links option.

alexandrul
  • 12,856
  • 13
  • 72
  • 99
  • 1
    This is the same as Marko Dumic's answer, but his is easier for an end-user while this one is easier (maybe not better) for an external app. – sep332 Nov 17 '08 at 16:01
  • 2
    Marko Dumic's answer didn't work in my case (Firefox 3.0.3 + Windows Server 2003 R2 SP2). – alexandrul Nov 18 '08 at 06:48
  • @MarkBerry just tested it: it works in Firefox 19 beta too :D – alexandrul Feb 19 '13 at 06:12
  • @machineghost could you try again, please? – alexandrul Aug 02 '19 at 07:15
  • On reviewing this question, I think what I'm doing might be different in a key way. I'm on 68.0 Firefox, Linux. I made `~/.mozilla/firefox/someletters.default/user.js`, added that line, ran `$('body').append('')` at the console and ... saw nothing on the page. But if I replace `someLocalFile.png` with a remote file I *do* see an image added. Also if I go directly to it the local file it works. I just can't see local files on non-local pages ... even with this pref change, which I thought/hoped would fix it. But I'm not actually doing links, sorry. – machineghost Aug 02 '19 at 19:56
  • @machineghost there are 3 lines that should be added, and one of them specifies the list of the allowed domains; creating html content with the console might now be exactly the expected behavior for this mechanism. – alexandrul Aug 03 '19 at 20:56
6

Reading at the solution given here, I followed the link Links to local pages do not work and for me, only this worked well (I am using wordpress for a personal FAQ on a local wamp installation):

  • Go to your "%Your Documents & Settings%\Application Data\Mozilla\Firefox\Profiles\%your profile%\"
  • edit the file "prefs.js"
  • add the following lines at the end of the document:

.

user_pref("capability.policy.localfilelinks.checkloaduri.enabled", "allAccess");
user_pref("capability.policy.localfilelinks.sites", "http://localhost");
user_pref("capability.policy.maonoscript.javascript.enabled", "allAccess");

You can leave the setting "security.checkloaduri" to its default value, and also the "security.fileuri.strict_origin_policy". Thanks to those 3 lines, you just make an exception for your local server.

Be careful, if you need to go back to that prefs.js file, note that Firefox will have ordered it alphabetically. So the 3 lines you will have added at the end will be somewhere at the beginning ;).

Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
Nicolas C.
  • 235
  • 4
  • 14
  • 3
    I think you miss the definition of the `localfilelinks` policy (see http://www.mozilla.org/projects/security/components/ConfigPolicy.html) `user_pref("capability.policy.policynames", "localfilelinks");` – Micha Wiedenmann Jan 29 '13 at 08:50
  • What does the `maonoscript` line do? Or was that supposed to be `policynames` as Micha suggests? – Mark Berry Feb 19 '13 at 02:09
2

You can load the LocalLink FireFox Add-On, which allows you to right-click on a local link and select 'Open in Foreground Window'. The other 'Open...' menu items are supposed to work, but don't for me.

http://locallink.mozdev.org/

Also, you can use NoScript, like Alex suggests, which enables normal clicking of local links. Thanks Alex.

Gordon Bell
  • 13,337
  • 3
  • 45
  • 64
2

Marko's solution should work for links that are also on the local filesystem, but I don't think it should allow an http:// page to link to a file:// page.

The issue for people linking from http:// pages is discussed here: http://kb.mozillazine.org/Links_to_local_pages_do_not_work along with an explanation of how to circumvent it and expose yourself to risk.

Richard
  • 21
  • 1
1

You can instead read the file off the disk and then send it in the Response from your page.

See this link for an example.

Geoff
  • 9,340
  • 7
  • 38
  • 48
  • see the link in my answer. They have a block of source code that shows how. Google "asp response file" and you'll find more samples. – Geoff Oct 10 '08 at 17:03
  • That worked !!! Thanks. Fyi all of the solutions that attempeted to change the browser setting did not work – Joe Oct 10 '08 at 17:55
  • FYI - The example works but will only pull files on the same server...the OPEN_FILE function fails if the files is on an external server. – Joe Oct 10 '08 at 19:15
1

Tonnes of thanks I wAs searching this solution since months,

::THis thing worked::

This could be turned off in firefox:

* type "about:config" in the address bar and accept "i'll be careful"
* find "security.checkloaduri" in older versions or "security.fileuri.strict_origin_policy" in newer versions of firefox and change the value to "false"
* restart firefox

::::

sunny
  • 11
  • 1
0

shouldn't you really store the pages in your application directory and reference them this way. http://SITENAME/Server/scanner/XYZ.pdf.

We do something similar with files stored all in one directory and just store the file name. we then create the link using the known folder name and append the file name. this works quite well.

Finally firefox is a lot more anal about the directions of the slashes in file names as well. Make sure they are all '/' rather than '\'.

Hope this helps.

wax eagle
  • 541
  • 11
  • 27
  • The files are not in a application directory. They reside on a separate server. I have the same set-up that you are have. Can you verify that you can produce an image using Firefox. If the displayed can you describe how you circumvented the security check that disables this functionality? – Joe Oct 10 '08 at 16:55
  • can you reference the server by IP address? if you have the access to the server you could make the folder the files are stored in a website in IIS and access them by the server's IP address. – wax eagle Oct 10 '08 at 17:41
0

beware of incompatibility with gmarks (google toolbar replacer) both local link and policy manager worked for me; local link is a little smoother, policy manager gives you more control

-1

file://localhost///servername/share/file.txt works for me on FF11

(from a local html file: file:///C:/index.html)

Alex L
  • 8,748
  • 5
  • 49
  • 75