@@ -51,6 +51,13 @@ abstract class Controller implements HttpServerInterface
51
51
*/
52
52
protected $ channelManager ;
53
53
54
+ /**
55
+ * The app attached with this request.
56
+ *
57
+ * @var \BeyondCode\LaravelWebSockets\Apps\App|null
58
+ */
59
+ protected $ app ;
60
+
54
61
/**
55
62
* Initialize the request.
56
63
*
@@ -176,8 +183,7 @@ protected function handleRequest(ConnectionInterface $connection)
176
183
177
184
$ laravelRequest = Request::createFromBase ((new HttpFoundationFactory )->createRequest ($ serverRequest ));
178
185
179
- $ this
180
- ->ensureValidAppId ($ laravelRequest ->appId )
186
+ $ this ->ensureValidAppId ($ laravelRequest ->get ('appId ' ))
181
187
->ensureValidSignature ($ laravelRequest );
182
188
183
189
// Invoke the controller action
@@ -220,7 +226,7 @@ protected function sendAndClose(ConnectionInterface $connection, $response)
220
226
*/
221
227
public function ensureValidAppId ($ appId )
222
228
{
223
- if (! App::findById ($ appId )) {
229
+ if (! $ appId || ! $ this -> app = App::findById ($ appId )) {
224
230
throw new HttpException (401 , "Unknown app id ` {$ appId }` provided. " );
225
231
}
226
232
@@ -252,9 +258,7 @@ protected function ensureValidSignature(Request $request)
252
258
253
259
$ signature = "{$ request ->getMethod ()}\n/ {$ request ->path ()}\n" .Pusher::array_implode ('= ' , '& ' , $ params );
254
260
255
- $ app = App::findById ($ request ->get ('appId ' ));
256
-
257
- $ authSignature = hash_hmac ('sha256 ' , $ signature , $ app ->secret );
261
+ $ authSignature = hash_hmac ('sha256 ' , $ signature , $ this ->app ->secret );
258
262
259
263
if ($ authSignature !== $ request ->get ('auth_signature ' )) {
260
264
throw new HttpException (401 , 'Invalid auth signature provided. ' );
0 commit comments