PKCE: What Can(Not) Be Protected


This post is about PKCE [RFC7636], a protection mechanism for OAuth and OpenIDConnect designed for public clients to detect the authorization code interception attack.
At the beginning of our research, we wrongly believed that PKCE protects mobile and native apps from the so called „App Impersonation" attacks. Considering our ideas and after a short discussion with the authors of the PKCE specification, we found out that PKCE does not address this issue.
In other words, the protection of PKCE can be bypassed on public clients (mobile and native apps) by using a maliciously acting app.

OAuth Code Flow


In Figure 1, we briefly introduce how the OAuth flow works on mobile apps and show show the reason why we do need PKCE.
In our example the user has two apps installed on the mobile phone: an Honest App and an Evil App. We assume that the Evil App is able to register the same handler as the Honest App and thus intercept messages sent to the Honest App. If you are more interested in this issue, you can find more information here [1].

Figure 1: An example of the "authorization code interception" attack on mobile devices. 

Step 1: A user starts the Honest App and initiates the authentication via OpenID Connect or the authorization via OAuth. Consequentially, the Honest App generates an Auth Request containing the OpenID Connect/OAuth parameters: client_id, state, redirect_uri, scope, authorization_grant, nonce, …. 
Step 2: The Browser is called and the Auth Request is sent to the Authorization Server (usually Facebook, Google, …).
  • The Honest App could use a Web View browser. However, the current specification clearly advice to use the operating system's default browser and avoid the usage of Web Views [2]. In addition, Google does not allow the usage of Web View browser since August 2016 [3].
Step 3: We asume that the user is authenticated and he authorizes the access to the requested resources. As a result, the Auth Response containing the code is sent back to the browser.

Step 4: Now, the browser calls the Honest App registered handler. However, the Evil App is registered on this handler too and receives the code.

Step 5: The Evil App sends the stolen code to the Authorization Server and receives the corresponding access_token in step 6. Now, the Evil App can access the authorized ressources.
  • Optionally, in step 5 the App can authenticate on the Authorization Server via client_id, client_secret. Since, Apps are public clients they do not have any protection mechanisms regarding the storage of this information. Thus, an attacker can easy get this information and add it to the Evil App.

    Proof Key for Code Exchange - PKCE (RFC 7636)

    Now, let's see how PKCE does prevent the attack. The basic idea of PKCE is to bind the Auth Request in Step 1 to the code redemption in Step 5. In other words, only the app generated the Auth Request is able to redeem the generated code.


    Figure 2: PKCE - RFC 7636 

    Step 1: The Auth Request is generated as previosly described. Additionally, two parameters are added:
    • The Honest App generates a random string called code_verifier
    • The Honest App computes the code_challenge=SHA-256(code_verifier)
    • The Honest App specifies the challenge_method=SHA256

    Step 2: The Authorization Server receives the Auth Request and binds the code to the received code_challenge and challenge_method.
    • Later in Step 5, the Authorzation Server expects to receive the code_verifier. By comparing the SHA-256(code_verifier) value with the recieved code_challenge, the Authorization Server verifies that the sender of the Auth Request ist the same as the sender of the code.
    Step 3-4: The code leaks again to the Evil App.

    Step 5: Now, Evil App must send the code_verifier together with the code. Unfortunatelly, the App does not have it and is not able to compute it. Thus, it cannot redeem the code.

     PKCE Bypass via App Impersonation

    Again, PKCE binds the Auth Request to the coderedemption.
    The question rises, if an Evil App can build its own Auth Request with its own code_verifier, code_challenge and challenge_method.The short answer is – yes, it can.

    Figure 3: Bypassing PKCE via the App Impersonation attack
    Step 1: The Evil App generates an Auth Request. The Auth Request contains the client_id and redirect_uri of the Honest App. Thus, the User and the Authorization Server cannot recognize that the Evil App initiates this request. 

    Step 2-4: These steps do not deviate from the previous description in Figure 2.

    Step 5: In Step 5 the Evil App sends the code_verifier used for the computation of the code_challenge. Thus, the stolen code can be successfully redeemed and the Evil App receives the access_token and id_token.

    OAuth 2.0 for Native Apps

    The attack cannot be prevented by PKCE. However, the IETF working group is currently working on a Draft describing recommendations for using OAuth 2.0 for native apps.

    References

    Vladislav Mladenov
    Christian Mainka (@CheariX)

    Related word


    1. Best Hacking Tools 2020
    2. Hacking Tools Free Download
    3. Hacking Tools Hardware
    4. Hacker Tools For Windows
    5. Hack Tools Github
    6. Hack Tools
    7. Hacking Tools For Windows Free Download
    8. Hacking Tools Windows
    9. Hack Website Online Tool
    10. Pentest Tools Apk
    11. Nsa Hack Tools
    12. Pentest Tools For Android
    13. Tools 4 Hack
    14. Pentest Tools For Mac
    15. What Are Hacking Tools
    16. Pentest Tools For Ubuntu
    17. Pentest Tools Nmap
    18. Hacking Tools Kit
    19. New Hack Tools
    20. Pentest Tools Free
    21. Hack Tools Download
    22. Hack Rom Tools
    23. Pentest Tools Nmap
    24. Pentest Tools Apk
    25. Pentest Tools For Mac
    26. Hackrf Tools
    27. Usb Pentest Tools
    28. Hacking Tools Mac
    29. Underground Hacker Sites
    30. Hacking Tools Pc
    31. Blackhat Hacker Tools
    32. New Hack Tools
    33. Termux Hacking Tools 2019
    34. Hack Tool Apk No Root
    35. Best Hacking Tools 2020
    36. Game Hacking
    37. Nsa Hacker Tools
    38. Pentest Tools Android
    39. Hacker Tools Free
    40. Bluetooth Hacking Tools Kali
    41. Physical Pentest Tools
    42. How To Install Pentest Tools In Ubuntu
    43. Hack Tool Apk
    44. Hack Tools
    45. Hacker Tools Apk Download
    46. Best Hacking Tools 2019
    47. What Are Hacking Tools
    48. Pentest Tools For Android
    49. Computer Hacker
    50. Hack Tools Github
    51. Hack Tools Pc
    52. Hacker Tools Mac
    53. Pentest Tools Github
    54. Beginner Hacker Tools
    55. Underground Hacker Sites
    56. Growth Hacker Tools
    57. Best Hacking Tools 2019
    58. Hack Tools Mac
    59. Pentest Tools
    60. Hacking Tools Mac
    61. Pentest Tools Url Fuzzer
    62. Hacker Tools For Mac
    63. Hack Tools Github
    64. Pentest Tools For Windows
    65. Hack Tools Online
    66. Hacking Tools Kit
    67. Nsa Hack Tools
    68. Hacker Tools For Mac
    69. Hacking App
    70. Termux Hacking Tools 2019
    71. Pentest Tools Online
    72. Pentest Tools For Ubuntu
    73. Best Hacking Tools 2019
    74. Kik Hack Tools
    75. Hacker Tool Kit
    76. Growth Hacker Tools
    77. Hacker Tools Linux
    78. How To Hack
    79. Wifi Hacker Tools For Windows
    80. Hacking Tools Download
    81. Hacker Tools Linux
    82. Pentest Tools Alternative
    83. Hacking Tools And Software
    84. Pentest Reporting Tools
    85. Bluetooth Hacking Tools Kali
    86. Hacking Tools Pc
    87. Underground Hacker Sites
    88. Tools For Hacker
    89. Nsa Hack Tools
    90. Pentest Tools Website
    91. Hacker Techniques Tools And Incident Handling
    92. Pentest Tools Review
    93. Pentest Tools For Android
    94. New Hacker Tools
    95. New Hack Tools
    96. Pentest Tools Url Fuzzer
    97. Hacker Tools Hardware
    98. Pentest Tools Bluekeep
    99. Hacker Tools Free Download
    100. Tools For Hacker
    101. Hack Tools For Mac
    102. Black Hat Hacker Tools
    103. Hacker Tools 2019
    104. Pentest Tools Framework
    105. Github Hacking Tools
    106. Hacking Tools Hardware
    107. Hack Tools Mac
    108. Beginner Hacker Tools
    109. Hacker Security Tools
    110. Hacking Tools Kit
    111. Hacking Tools 2019
    112. Hacking Tools For Windows 7
    113. Hacking Tools Download
    114. Hacker Tools For Windows
    115. Tools 4 Hack
    116. What Is Hacking Tools
    117. Pentest Tools Online
    118. Hack Tools For Ubuntu
    119. Hack Rom Tools
    120. Pentest Tools Kali Linux
    121. Hack Tools For Mac
    122. Hacker Tools 2020
    123. Pentest Tools Port Scanner
    124. Hack Rom Tools
    125. Hacker Tools Github
    126. Hacker Tools Free Download
    127. New Hack Tools
    128. Pentest Tools Online
    129. Pentest Tools Online
    130. Hacker Tools For Windows
    131. Pentest Tools Online
    132. Computer Hacker
    133. Game Hacking
    134. Hack App
    135. Hacking Tools Online
    136. Computer Hacker
    137. Hacking Tools Pc
    138. Hacking Tools For Windows
    139. Hack Tools Github
    140. Hack Rom Tools
    141. Game Hacking
    142. Pentest Tools Windows
    143. Hacker Tools Online
    144. Pentest Tools Open Source
    145. Bluetooth Hacking Tools Kali
    146. Hacking Tools Name
    147. Hack Tools Online
    148. Pentest Automation Tools
    149. Pentest Tools Linux
    150. Hack Tools For Pc
    151. Computer Hacker
    152. Pentest Tools Bluekeep
    153. Hack Tools 2019
    154. Physical Pentest Tools
    155. Termux Hacking Tools 2019
    156. Hacker Tools Free Download
    157. Hack Tools Pc
    158. Hacker Tools Apk
    159. Hacking Tools 2020
    160. Pentest Tools Android
    161. How To Hack
    162. Hack Tools Mac
    163. Hacker Tools List
    164. Hack Rom Tools
    165. Wifi Hacker Tools For Windows
    166. Hackers Toolbox
    167. Hack Rom Tools
    168. Pentest Tools Android
    169. Hack Tools For Pc
    170. Pentest Tools Online
    171. Hack Tools For Games
    172. Black Hat Hacker Tools
    173. Hacking Tools 2020
    174. Hack Tool Apk
    175. Hacker Hardware Tools
    176. Hacking Tools For Pc
    177. Hacking Tools Usb
    178. Pentest Tools Review

    تعليقات