如何防止外部用户查看文档文件 [英] How to prevent external users from viewing document files

查看:65
本文介绍了如何防止外部用户查看文档文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了一个在线系统,允许用户使用ColdFusion下载PDF文件。用户必须先登录,然后才能下载文件(PDF和Microsoft Office文档)。 (此应用程序仅适用于我们公司的员工。)

I've built an online system that allows users to download PDF files using ColdFusion. Users have to log in before they can download the files (PDF & Microsoft Office documents). (This application is only for our company staff.)

但是,直到今天,我才发现可以访问Internet的任何人都可以查看文件。在Google搜索中仅使用某些关键字(例如 Medical Form myCompanyName(医疗表格myCompanyName)),他们就可以使用浏览器查看PDF文件。

However, only today I found out that anyone with internet access can view the files. With only certain keywords such as 'Medical Form myCompanyName' in a Google search, they can view the PDF files using the browser.

如何防止这种情况?

更新

这就是我的问题。我已经为所有PDF文件创建了一个文件夹。使用数据库中的ID调用每个文件。如果假设用户要查看医疗表格,则链接为: http:/ /myApplication.myCompanyName/forms.cfm?Department=Account&filesID=001

如果用户复制此网址&从系统注销,他/她将无法查看此文件。(将显示登录页面)

if the user copy this url & log out from system, he/she will not be able to view this file.(login page will be displayed)

但是,没有url,其他互联网用户仍然可以仅通过在网上搜索即可查看pdf文件,搜索引擎将提供一个无需登录即可将其直接定向到文件夹本身的链接。

However, without the url, other internet users sstill can view the pdf files just by search it on the net, and the search engine will gives a link that direct it to the folder itself, without having to login.

示例:
医疗表格的pdf文件存储在名为Document的文件夹中。当互联网用户搜索医疗表格时,搜索引擎会将其链接到: http:// myApplication。 myCompanyName / Document / Medical%20Form.pdf

我们在此文件夹中有很多PDF文件,并且大多数是机密的,并且仅用于内部查看。在php中,我们可以使用.htaccess禁用此功能。我想知道是否有类似的东西可以进行冷熔?

we have lots of PDF files in this folder and most of it are confidential, and for internal view purpose only. in php, we can disable this by using .htaccess. i'd like to know if there's anything like this for coldfusion?

推荐答案

您可以通过以下代码通过单行代码发送文件:

You can send files through the code with single line like this:

<cfif isAuthorized>
    <cfcontent file="/path/to/files/outside/of/web/root/Form.pdf" type="application/pdf" reset="true" />
</cfif>

ColdFusion FTW,对。

ColdFusion FTW, right.

<罢工>请注意,处理大文件(例如100MB以上)可能会导致一些问题,因为文件在发送之前就被推入RAM。就像Mike的回答所解释的那样,这似乎不再正确。

Please note that handling large files (say, 100MB+) may cause some problems, because files being pushed to RAM before sending. Looks like this is not correct any more, as Mike's answer explains.

另一种选择是,如果要强制下载,则使用 x-application 这样的内容类型。

Another option is to use content type like x-application if you want to force download.

UPD

您想将此代码放入文件(例如file.cfm)并将其用于PDF链接。这样的事情:

You want to put this code into the file (let's say file.cfm) and use it for PDF links. Something like this:

<a href="file.cfm?filename=Xyz.pdf">Download file Xyz.pdf</a>

file.cfm:

<!--- with trailing slash --->
<cfset basePath = "/path/to/files/outside/of/web/root/" />

<cfif isAuthorized AND StructKeyExists(url, "filename") 
      AND FileExists(basePath & url.filename) 
      AND isFile(basePath & url.filename) 
      AND GetDirectoryFromPath(basePath & url.filename) EQ basePath>
    <cfcontent file="#basePath##url.filename#" type="application/pdf" reset="true" />
<cfelse>
    <cfoutput>File not found, or you are not authorized to see it</cfoutput>
</cfif>

UPD2

添加了 GetDirectoryFromPath(basePath&.url.filename)EQ basePath ,可以轻松,快速地避免上述安全问题。

Added GetDirectoryFromPath(basePath & url.filename) EQ basePath as easy and quick protection from the security issue mentioned.

我个人通常使用ID /数据库方法,尽管此答案最初只是作为简单的指导,而不是真正的综合解决方案。

Personally I usually use ID/database approach, though this answer was initially intended as simple guidance, not really compehensive solution.

这篇关于如何防止外部用户查看文档文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆