为何无Bearer令牌的GET请求可访问OAuth2.0保护文件?
背景与细节
我投递求职申请后收到了Hirevue链接,正在研究该页面发起的HTTP请求。出于隐私保护,我无法提供页面URL及相关请求的目标URL,这可能会限制能提供的帮助。
通过浏览器开发者工具,我发现页面会向格式为https://COMPANY.hirevue.com/api/internal/candidates/interviews/INTERVIEW_CODE/?future-practice-questions&include=answers,reuses,sections,poc&_=UNIQUE_VALUE的API端点发送GET请求以获取包含个人数据的JSON文件,请求头中包含Authorization头:Authorization: Bearer TOKEN_VALUE。
据我理解,这意味着该JSON文件受OAuth 2.0协议保护,采用Bearer授权方案传输令牌以获取访问权限,因此似乎必须在Authorization头中指定正确的Bearer令牌才能访问该文件。
问题
然而,当我发送带有空Authorization头(即Authorization: )的GET请求时,仍能访问该JSON文件。
我使用以下Python脚本发送请求:
import requests, json def get_json(url, auth_token=None): # authorization header: scheme is Bearer token response = requests.get(url, auth=auth_token) try: return response.json() except json.JSONDecodeError: print(f"Response to GET request:\n\n{response.content}\n\nExpected Reponse: a JSON string") if __name__ == "__main__": # auth token type and token value for API GET request my_autho = ('', '') # redacted URL for my privacy url = "https://COMPANY.hirevue.com/interviews/INTERVIEW_CODE" data = get_json(url, my_autho) print(data)
当我省略Authorization头(即调用get_json(url))时,会收到404页面,因此我认为发送空头时也应得到同样结果。
即我预期会触发JSONDecodeError异常(已被get_json捕获):
Response to GET request: b'\n\n<html>\n <head>\n <title>Error 404: Not found | HireVue</title>\n <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\n <meta http-equiv="X-UA-Compatible" content="IE=7; IE=8; IE=9" />\n <link\n href="https://static.hirevue.com/static/14b0bc1/fonts/Inter-3.15/inter.css"\n rel="stylesheet"\n />\n <link rel="stylesheet" type="text/css" href="https://static.hirevue.com/static/14b0bc1/css/build/bootstrap/bootstrap.css">\n <style type="text/css">\n body {\n text-align:center;\n font-family: Arial, Helvetica, Sans-Serif;\n }\n </style>\n </head>\n <body>\n <h1>Oops! We couldn't find that Page!</h1>\n <h3>Error 404</h3>\n <p>Please go back and try again.</p>\n <img src="https://static.hirevue.com/static/14b0bc1/img-new/hv-logo-color.png" alt="HireVue" border="0">\n </body>\n</html>\n' Expected Reponse: a JSON string
但实际输出却是JSON字符串。为何无Bearer令牌仍能访问受OAuth 2.0保护的JSON文件?
参考文献:
- HTTP authentication - MDN Web Docs
- IETF Datatracker - The OAuth 2.0 Authorization Framework: Bearer Token Usage
内容的提问来源于stack exchange,提问作者übermensch

