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"
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度