简体   繁体   English

防止直接访问json文件

[英]prevent direct access to json file

Trying to deny to direct access to a json file, tried: 尝试deny直接访问json文件,尝试:

RewriteRule ^(api/|category\.json) - [F,L,NC]

but not working. 但不起作用。

I used this file for an ajax call but i don't want anyone can access to this file directly. 我使用此文件进行ajax调用,但我不希望任何人都可以直接访问此文件。

$.ajax({
type: "POST",
dataType: 'json',
url: 'api/category.json',
success: function(data){
$.each(data, function(i,v) {
// do something
});

Wondering is there any method to do this? 想知道有什么方法可以做到这一点吗? via htaccess or httpd.conf or etc? 通过htaccesshttpd.conf等?

AFAIK, if you can access the file with an HTTP GET command, which you'd have to do with the Ajax call, then you can also access the file and download it directly. AFAIK,如果您可以使用HTTP GET命令访问该文件(必须使用Ajax调用),那么您还可以访问该文件并直接下载。

Sorry. 抱歉。

However, you can at least configure the Apache server to not allow direct indexing of that directory. 但是,您至少可以将Apache服务器配置为不允许该目录的直接索引。 Search for the "Options" directive in the httpd.conf file, and if it has an "Indexes" tag, either remove it or prepend a minus sign, eg, 在httpd.conf文件中搜索“ Options”指令,如果它具有“ Indexes”标记,则将其删除或添加减号,例如,

Options -Indexes

That way, at least people won't know the file is there just by remotely perusing the directories. 这样,至少人们仅通过远程浏览目录就不会知道文件在那里。

You can "minimize" your Javascript file (the one containing your Ajax call) by removing all comments and whitespace. 您可以通过删除所有注释和空格来“最小化”您的Javascript文件(包含Ajax调用的Javascript文件)。 Search the web for tools that do this. 在网上搜索用于执行此操作的工具。 Because, if somebody can read your Javascript, they can see exactly that your Ajax is fetching "api/category.json"; 因为,如果有人可以阅读您的Javascript,他们可以确切地看到您的Ajax正在获取“ api / category.json”; then of course they can too. 那么他们当然也可以。

They still can read the "minimized" script anyway, plus there are tools to "de-minimize" it, but it may be enough trouble so that most people won't bother. 他们仍然仍然可以阅读“最小化”脚本,还有一些工具可以使它“最小化”,但这可能就足够麻烦了,以至于大多数人都不会去理会。

I'd suggest you try to avoid putting any really deep dark secrets in that file, because, bottom line, if your Ajax can fetch it, so can anybody else. 我建议您尽量避免在该文件中放置任何真正深层的秘密,因为最重要的是,如果您的Ajax可以获取它,那么其他人也可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM