我想根据 web.py 中的某种形式的身份验证有选择地隐藏一些资源,但是它们的存在是通过对我尚未实现的任何 HTTP 方法的 405 响应来揭示的。
这是一个例子:
import web
urls = (
'/secret', 'secret',
)
app = web.application(urls, globals())
class secret():
def GET(self):
if web.cookies().get('password') == 'secretpassword':
return "Dastardly secret plans..."
raise web.notfound()
if __name__ == "__main__":
app.run()
当发出未定义的方法请求时,会显示资源:
$ curl -v -X DELETE http://localhost:8080/secret
...
> DELETE /secret HTTP/1.1
...
< HTTP/1.1 405 Method Not Allowed
< Content-Type: text/html
< Allow: GET
...
我可以对 HTTP 规范中的其他常用方法实施相同的检查,但有创意的恶棍可能会发明自己的方法:
$ curl -v -X SHENANIGANS http://localhost:8080/secret
...
> SHENANIGANS /secret HTTP/1.1
...
< HTTP/1.1 405 Method Not Allowed
< Content-Type: text/html
< Allow: GET
...
有没有办法在 web.py 类中为任何 HTTP 方法实现 catch all 方法,这样我就可以确保运行安全检查?
或者有没有其他方法可以隐藏这些资源?