-
Notifications
You must be signed in to change notification settings - Fork 242
[Log Rocket] /broadcasting/auth 403 on multiple customers #8737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
32311fc
da6323b
b375796
92b54eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| <?php | ||
|
|
||
| namespace ProcessMaker\Http\Middleware; | ||
|
|
||
| use Closure; | ||
| use Illuminate\Support\Facades\Auth; | ||
| use Illuminate\Support\Facades\Log; | ||
|
|
||
| class BroadcastAuthDebug | ||
| { | ||
| /** | ||
| * Log broadcast auth requests that fail (403, 401, 500) for debugging intermittent issues. | ||
| * Enable with BROADCAST_AUTH_DEBUG=true in .env | ||
| * | ||
| * @param \Illuminate\Http\Request $request | ||
| * @param Closure $next | ||
| * @return mixed | ||
| */ | ||
| public function handle($request, Closure $next) | ||
| { | ||
| $response = $next($request); | ||
|
|
||
| if (!env('BROADCAST_AUTH_DEBUG', false)) { | ||
| return $response; | ||
| } | ||
|
|
||
| if ($response->getStatusCode() < 400) { | ||
| return $response; | ||
| } | ||
|
|
||
| $user = Auth::user(); | ||
| $channelName = $request->input('channel_name'); | ||
| $channelInfo = $this->parseChannelInfo($channelName); | ||
|
|
||
| Log::error('Broadcast auth failed', [ | ||
| 'status' => $response->getStatusCode(), | ||
| 'user_id' => $user?->id, | ||
| 'user_type' => $user ? get_class($user) : null, | ||
| 'user_is_anonymous' => $user && method_exists($user, 'isAnonymous') ? $user->isAnonymous : null, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 'has_session' => $request->hasSession(), | ||
| 'session_id' => $request->session()?->getId(), | ||
| 'channel_name' => $channelName, | ||
| 'channel_type' => $channelInfo['type'], | ||
| 'channel_resource_id' => $channelInfo['id'], | ||
| 'user_channel_mismatch' => $channelInfo['type'] === 'User' && $user && $channelInfo['id'] | ||
| ? (string) $user->id !== (string) $channelInfo['id'] | ||
| : null, | ||
| 'cookie_present' => $request->hasCookie(config('session.cookie')), | ||
| 'ip' => $request->ip(), | ||
| 'origin' => $request->header('Origin'), | ||
| 'referer' => $request->header('Referer'), | ||
| 'user_agent' => $request->userAgent(), | ||
| 'socket_id' => $request->input('socket_id'), | ||
| 'response_body' => $this->getResponseBody($response), | ||
| 'timestamp' => now()->toIso8601String(), | ||
| ]); | ||
|
|
||
| return $response; | ||
| } | ||
|
|
||
| private function parseChannelInfo(?string $channelName): array | ||
| { | ||
| if (!$channelName) { | ||
| return ['type' => null, 'id' => null]; | ||
| } | ||
| // Strip tenant prefix: tenant_X.ProcessMaker.Models.User.14 -> ProcessMaker.Models.User.14 | ||
| $channel = preg_replace('/^tenant_\d+\./', '', $channelName); | ||
| if (preg_match('/ProcessMaker\.Models\.User\.(\d+)/', $channel, $m)) { | ||
| return ['type' => 'User', 'id' => $m[1]]; | ||
| } | ||
| if (preg_match('/ProcessMaker\.Models\.ProcessRequest\.(\d+)/', $channel, $m)) { | ||
| return ['type' => 'ProcessRequest', 'id' => $m[1]]; | ||
| } | ||
| if (preg_match('/ProcessMaker\.Models\.ProcessRequestToken\.(\d+)/', $channel, $m)) { | ||
| return ['type' => 'ProcessRequestToken', 'id' => $m[1]]; | ||
| } | ||
|
|
||
| return ['type' => 'other', 'id' => null]; | ||
| } | ||
|
|
||
| private function getResponseBody($response): ?string | ||
| { | ||
| $content = $response->getContent(); | ||
| if (is_string($content) && strlen($content) < 500) { | ||
| return $content; | ||
| } | ||
|
|
||
| return $content ? '[truncated]' : null; | ||
| } | ||
| } | ||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Direct
env()call fails with cached configMedium Severity
env('BROADCAST_AUTH_DEBUG', false)is called directly instead of through a config value. In production Laravel deployments wherephp artisan config:cachehas been run, the.envfile isn't loaded, soenv()will always return the defaultfalse. SinceBROADCAST_AUTH_DEBUGisn't registered in any config file, this middleware can never be activated in a cached-config environment — exactly the production scenario it's meant to debug.