dongshi9526 2015-06-06 08:08
浏览 88
已采纳

webapp的安全通用配置文件

I would like to keep all config options for a webapp in one file. (pathes, passwords, options which are read by php, sass (during compilation), maybe grunt,..)

I like the JSON format since its very clear and almost anything can parse json. But by default .json files can be downloaded.

Can I safely prevent that by giving the file a .json.php extension?

What are the drawbacks? Better Approaches?

  • 写回答

1条回答 默认 最新

  • doutan3040 2015-06-06 13:04
    关注

    To prevent the file being downloaded, generally the way to go is to store it in a directory that is not served by the web server. I don't know what setup you're in, but assuming an Apache setup, if for example your .php files are served from a directory /home/user/htdocs, you could create a directory /home/user/config, ensure that it is readable by the webserver, and store the .json files there.

    Another approach, again assuming Apache, would be to create an .htaccess file containing the following (inspired by this answer):

    RedirectMatch 404 \.json$ 
    

    This would not only prevent downloading any and all .json files in the directory, but hide their very existence.

    It might just be possible to do it the way you suggested, by storing the file with a .json.php extension, although this would not be a recommended approach. For this to work, the file has to be valid PHP but it must obviously be valid JSON as well and we are hampered somewhat by the fact that JSON does not allow comments. Something like the following would stop the PHP interpreter soon after the start of the file, before spilling your secrets:

    {
      "<?php exit('Access denied'); ?>": null,
      "password": "secret"
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog