Skip to content

Commit d4f3fec

Browse files
committed
Only do permission validations on server
context.SenderId will be the server for a client receiving the proxied message, so the checks will not be accurate. The checks are also unnecessary considering the checks have already been done by the server.
1 parent 82a80db commit d4f3fec

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

com.unity.netcode.gameobjects/Runtime/Messaging/Messages/ProxyMessage.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,26 @@ public unsafe void Handle(ref NetworkContext context)
4343
}
4444
var observers = networkObject.Observers;
4545

46-
var networkBehaviour = networkObject.GetNetworkBehaviourAtOrderIndex(WrappedMessage.Metadata.NetworkBehaviourId);
47-
48-
RpcInvokePermission permission = NetworkBehaviour.__rpc_permission_table[networkBehaviour.GetType()][WrappedMessage.Metadata.NetworkRpcMethodId];
49-
bool hasPermission = permission switch
46+
// Validate message if server
47+
if (networkManager.IsServer)
5048
{
51-
RpcInvokePermission.Anyone => true,
52-
RpcInvokePermission.Server => context.SenderId == networkManager.LocalClientId,
53-
RpcInvokePermission.Owner => context.SenderId == networkBehaviour.OwnerClientId,
54-
_ => false,
55-
};
49+
var networkBehaviour = networkObject.GetNetworkBehaviourAtOrderIndex(WrappedMessage.Metadata.NetworkBehaviourId);
5650

57-
// Do not handle the message if the sender does not have permission to do so.
58-
if (!hasPermission)
59-
{
60-
return;
61-
}
51+
RpcInvokePermission permission = NetworkBehaviour.__rpc_permission_table[networkBehaviour.GetType()][WrappedMessage.Metadata.NetworkRpcMethodId];
52+
bool hasPermission = permission switch
53+
{
54+
RpcInvokePermission.Anyone => true,
55+
RpcInvokePermission.Server => context.SenderId == networkManager.LocalClientId,
56+
RpcInvokePermission.Owner => context.SenderId == networkBehaviour.OwnerClientId,
57+
_ => false,
58+
};
59+
60+
// Do not handle the message if the sender does not have permission to do so.
61+
if (!hasPermission)
62+
{
63+
return;
64+
}
6265

63-
if (networkManager.IsServer)
64-
{
6566
WrappedMessage.SenderClientId = context.SenderId;
6667
}
6768

0 commit comments

Comments
 (0)