V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
yadam
V2EX  ›  问与答

nginx 配置 rewrite 直接读文件的安全性问题

  •  
  •   yadam · Aug 10, 2015 · 1760 views
    This topic created in 3919 days ago, the information mentioned may be changed or developed.

    在ngingx下面添加了如下的配置

    if ($request_uri ~* "/foo\?bar=(.*)") {
        rewrite .* $1.json? permanent;
    }
    

    目的是读取特定目录下 bar.json 的文件
    我自己认为配置中加了 json 后缀, 就不会有遍历问题, 但心里不踏实

    google了 nginx Directory traversal attack 没找到有效信息,
    nginx security 关键字看到下面两篇比较好的文章,但是还是没有帮到
    Nginx Security – The definitive Guide to secure your Nginx server
    Nginx Pitfalls

    请教:
    1. 这个配置是否有文件遍历的危险?
    2. 能否给一些nginx安全相关的文档?

    2 replies    2015-08-11 15:10:01 +08:00
    invite
        1
    invite  
       Aug 11, 2015   ❤️ 1
    问:既然要搞成静态json文件,为什么URI不能直接写成静态的?用看似动态的干嘛?
    yadam
        2
    yadam  
    OP
       Aug 11, 2015
    @invite
    需求方是这么要求的, 因为后面bar的值会很多, 可能会使用php或者什么动态响应, 现在搭的临时测试环境.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   879 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 22:45 · PVG 06:45 · LAX 15:45 · JFK 18:45
    ♥ Do have faith in what you're doing.