AWS API gateway returns 400 error when square bracket (“[”, “]”) is in path

♀尐吖头ヾ 提交于 2019-12-11 19:16:29

问题


I set up API gateway with Lambda Integration and came across this problem.

OK case

Request URI: https://api-gateway-host/stage/hoge

hoge is not a configured path so this returned:

OK: missing authentication token

NG case

Request URI: https://api-gateway-host/stage/ho[ge

The path is ho"["ge. It's also not a configured path so I expected same result but:

NG: 400

All of /ho]ge, /ho[]ge, /ho[g]e, /hoge[] and /hoge[1] return the same result. Actually if square brackets are in "query" like /hoge?q=hoge[], it can be accepted.

Does anyone know the reason? Is it a Api gateway's limitation? I think it doesn't violate RFC.

Environment

  • AWS us-east-1
  • Basic setup of Lambda Proxy with empty lambda function
  • No request validate (I enabled request validation but the result was same)
  • Browser is Google Chrome (same in Curl)

回答1:


Actually, square brackets are not allowed in an API gateway URL. This is a limitation of the service and does not align with RFC standards.

  • See this AWS thread which discusses this limitation in 2016.
  • See this AWS unanswered question from just this month (Aug 2018) that again asks when square brackets will be supported.

To get around this limitation, you can encode square brackets, as detailed in this thread.



来源:https://stackoverflow.com/questions/51941139/aws-api-gateway-returns-400-error-when-square-bracket-is-in-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!