简体   繁体   English

SSL'ed JSON API是否使用cookie进行身份验证,而nonce通常是安全的?

[英]Is a SSL'ed JSON API that uses cookies for authentication and nonces generally secure?

If I build an SSL'ed API that authenticates with a session ID held within a cookie, adds a nonce as a query parameter, and always responds with a JSON 'Object' response (as opposed to a JSONP-style response with a callback), is it secure in general, and in particular against XSRF? 如果我构建一个使用cookie中保存的会话ID进行身份验证的SSL,则添加一个nonce作为查询参数,并始终使用JSON“Object”响应进行响应(而不是使用回调的JSONP样式响应) ,它一般是安全的,特别是对抗XSRF吗?

The intent with such an API to only have it available to pages on my own domain, and to be free to expose private data (such as username and emails) through this API (but not be consumable by other domains)--and retain a reasonable amount of simplicity for developers on the team. 这种API的目的只是让它可以在我自己的域上的页面上使用,并且可以通过这个API自由地公开私人数据(例如用户名和电子邮件)(但不能被其他域消费) - 并保留一个团队开发人员的合理程度。

Let me at least share what I understand about this approach, and why I think it's secure. 让我至少分享一下我对这种方法的理解,以及为什么我认为它是安全的。 Please enlight me if wrong!: 如果错的话惹我!

  • A <script> tag dropped on a 3rd-party domain to our site would send my cookies, but would not be able to parse the JSON object response ( and the response would always deliberately be a JSON object at the top level ). 在我们网站的第三方域上删除的<script>标记将发送我的cookie,但无法解析JSON对象响应( 并且响应总是故意成为顶级的JSON对象 )。 Also, I need to make sure that API calls that affect state on the server are all protected by non-GET method access, because <script> tags must use GET and so can not cause havok by attempt to call state-changing calls (in other words, the API would be adherent to REST in so far as HTTP methods go). 此外,我需要确保影响服务器状态的API调用都受到非GET方法访问的保护,因为<script>标记必须使用GET,因此不能通过尝试调用状态更改调用来导致havok(在换句话说,就HTTP方法而言,API将与REST一致。 Also, I deliberately do not support JSONP because it would be a security hole. 另外,我故意不支持JSONP,因为这将是一个安全漏洞。
  • Man-in-the-middle used to hijack cookies (the session) is not a concern because I'm using SSL with valid certificates. 用于劫持cookie(会话)的中间人不是一个问题,因为我使用SSL和有效的证书。
  • Replay attacks are a temporally limited concern because of the use of a nonce will limit how long one could send in a replay of an HTTPS request, because the server will make sure that the API call is only valid for a small amount of time in a typical nonce-validating way. 重放攻击是一个暂时受到限制的问题,因为使用nonce将限制重放HTTPS请求所需的时间,因为服务器将确保API调用仅在一小段时间内有效。典型的nonce验证方式。
  • XMLHttpRequest can not make cross-domain calls, so it can't request anything from my site. XMLHttpRequest无法进行跨域调用,因此无法从我的站点请求任何内容。
  • CORS (Cross ORigin Resource Sharing) is not of concern because I don't have a crossdomain.xml file or any other advertisement of cross-domain support associated with HTML 5. CORS(交叉ORigin资源共享)并不重要,因为我没有crossdomain.xml文件或任何其他与HTML 5相关的跨域支持广告。
  • An iframe in a 3rd-party site doesn't matter because even though it can load my page graphically, the host site can't access any data within that iframe, and because I've made no attempt to support cross-domain iframe communication (so they can attempt to set # on the iframe URL like folks do to enable communication between cross-domain iframes, but my page won't be responsive to it). 第三方网站中的iframe无关紧要,因为即使它可以图形方式加载我的页面,主机网站也无法访问该iframe中的任何数据,并且因为我没有尝试支持跨域iframe通信(因此,他们可以尝试在iframe网址上设置#,就像人们一样,以启用跨域iframe之间的通信,但我的网页将无法响应它)。

EDIT: A nonce would also protect against even cross-domain GET requests (ie, <script> tags) as russau says. 编辑:一个随机数也可以防止甚至跨域GET请求(即<script>标签),如russau所说。 In thinking on that specifically, I like the idea of asking for a nonce in a 'POST' API call that is not itself nonce protected; 在具体考虑这一点时,我喜欢在“POST”API调用中要求nonce的想法本身不受nonce保护; it should be the case that only XmlHTTPRequest's on the same domain can then generate a nonce to begin with. 应该是这样的情况,只有同一个域上的XmlHTTPRequest可以生成一个nonce开头。 This seems to be a simple way of making the generation of nonce's developer-friendly. 这似乎是使nonce的开发人员友好的一代的简单方法。 (ie, nothing server-side for the website/javascript developers--just ask for your nonce from the same API you are using to develop against, and make requests with that nonce until you get a 'bad nonce' response--then ask for a new one, and repeat. (即,对于网站/ javascript开发人员来说,没有任何服务器端 - 只需要从您使用的相同API中查询你的nonce,并在你收到'坏nonce'响应之前使用该nonce发出请求 - 然后询问换一个新的,重复一遍。

The only attack I can imagine is DNS rebinding . 我能想到的唯一攻击是DNS重新绑定 If your webserver is configured properly (a name-based vhost should be sufficient) you should be pretty safe though. 如果您的网络服务器配置正确(基于名称的虚拟主机应该足够),您应该非常安全。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM