-
Notifications
You must be signed in to change notification settings - Fork 244
[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
Open
marcoAntonioNina
wants to merge
6
commits into
develop
Choose a base branch
from
bugfix/FOUR-24910
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+170
−6
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
32311fc
Add BroadcastAuthDebug middleware for logging failed broadcast auth r…
marcoAntonioNina da6323b
Merge branch 'develop' of github.com:ProcessMaker/processmaker into b…
marcoAntonioNina b375796
Updated broadcasting configuration to ensure authentication requests …
marcoAntonioNina 92b54eb
Enhanced BroadcastAuthDebug middleware for improved error logging and…
marcoAntonioNina ab45b81
Use config to read auth_debug
marcoAntonioNina 9ff5e1f
Merge branch 'develop' of github.com:ProcessMaker/processmaker into b…
marcoAntonioNina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 (config/broadcasting.php) | ||
| * | ||
| * @param \Illuminate\Http\Request $request | ||
| * @param Closure $next | ||
| * @return mixed | ||
| */ | ||
| public function handle($request, Closure $next) | ||
| { | ||
| $response = $next($request); | ||
|
|
||
| if (!config('broadcasting.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, | ||
| '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; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
method_existscheck fails forisAnonymouspropertyMedium Severity
isAnonymousis defined as a public property (public $isAnonymous = true;) onAnonymousUser, not a method. Usingmethod_exists($user, 'isAnonymous')will always returnfalse, souser_is_anonymouswill always be logged asnull— even for anonymous users. This undermines the debug middleware's ability to diagnose the exact 403 scenario it was built to investigate. The check needsproperty_existsinstead.