Marsの5εcur1ty備忘録

不定期的にCTF、脆弱性検証、バグバウンティレポート分析など、情報セキュリティを中心とした技術ブログを更新します。

A note for reading 'Mastering Modern Web Penetration Testing', Chapter 1

Chapter 1

SOP(Same-origin policy)

Explanation by Wikipedia:
In computing, the same-origin policy is an important concept in the web application security model. Under the policy, a web browser permits scripts contained in a first web page to access data in a second web page, but only if both web pages have the same origin. An origin is defined as a combination of URI scheme, host name, and port number. This policy prevents a malicious script on one page from obtaining access to sensitive data on another web page through that page's Document Object Model.

Reference:
Same-origin policy - Wikipedia

This change allowed when the current page is the subset of the main domain.
If the current page isn't the subset of the main domain, an error message will be shown in the console log.

  • Quirks with Internet Explorer
    It skips the policy checks in the following situation:
  • The origin falls under the Trust Zone. e.g. internal corporate websites.
  • IE doesn't give any importance to port number. e.g. port 8081 and port 8080 can be considered as the same origin.

Possible bugs:
1. SOP bypass in IE for the port number.
2. An SOP bypass in Firefox abusing the PDF reader. (CVE-2015-4495)
https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2015-4495

  • Cross-domain messaging
    Sometimes, there exists a need to communicate across different origins.
    Cross-domain messaging(CDM) allows sending messages or data across different origins.

  • AJAX and the same-origin policy
    AJAX allows the browser to silently exchange data with the server without reloading the page.
    AJAX works using the XMLHTTPRequest() method of JS.
    XMLHttpRequestXMLHttpRequest (XHR) is an API in the form of an object whose methods transfer data between a web browser and a web server.

XMLHttpRequest - Wikipedia

CORS(Cross-Origin Resource Sharing)

CORS allows cross-domain HTTP data exchange, which means a page running at origin A can send/receive data from a server at origin B.

'Access-Control-Allow-Origin' will allow Cross-Origin Resource Sharing.
e.g.

Access-Control-Allow-Origin: *.example.com
Access-Control-Allow-Methods: OPTIONS, GET, POST
Access-Control-Allow-Headers: X-custom
Access-Control-Allow-Credentials: true

f:id:z773733850:20190530132423p:plain

Copyright Mars 2019