@@ -103,31 +103,15 @@ protected function loadOAuthAccountData() {
103103 $ token_header = sprintf ('Bearer %s ' , $ this ->getAccessToken ());
104104 $ future ->addHeader ('Authorization ' , $ token_header );
105105 list ($ body ) = $ future ->resolvex ();
106- $ data = $ this ->decodeJWT ($ body );
107- return $ data ['result ' ];
108- }
109-
110- private function decodeJWT ($ jwt ) {
111- list ($ headb64 , $ bodyb64 , $ sigb64 ) = explode ('. ' , $ jwt );
112-
113- $ header = json_decode ($ this ->urlsafeB64Decode ($ headb64 ));
114- $ body = json_decode ($ this ->urlsafeB64Decode ($ bodyb64 ));
115- $ sig = $ this ->urlsafeB64Decode ($ sigb64 );
116-
117- $ expect_sig = hash_hmac (
118- 'sha256 ' ,
119- "$ headb64. $ bodyb64 " ,
120- $ this ->getConsumerSecret ()->openEnvelope (),
121- true );
122-
123- // MediaWiki will only use sha256 hmac (HS256) for now.
124- // This checks that an attacker doesn't return invalid JWT signature type.
125- if ($ header ->alg !== 'HS256 ' ||
126- !$ this ->compareHash ($ sig , $ expect_sig )) {
127- throw new Exception ('Invalid JWT signature. ' );
128- }
129-
130- return $ body ;
106+ try {
107+ $ data = phutil_json_decode ($ body );
108+ return $ data ['result ' ];
109+ } catch (PhutilJSONParserException $ ex ) {
110+ throw new Exception (
111+ pht (
112+ 'Expected valid JSON response from MediaWiki request ' ),
113+ $ ex );
114+ }
131115 }
132116
133117 protected function willProcessTokenRequestResponse ($ body ) {
0 commit comments