Skip to content

armgit / meet

Public Imported from GitHub
0

Open source video conferencing app powered by LiveKit. Built with Django and React.

๐Ÿš‘๏ธ(frontend) throttle emoji reaction sending to prevent DoS attacks

lebaudantoine9e27d0f34555
diff --git a/src/frontend/src/features/rooms/livekit/components/controls/ReactionsToggle.tsx b/src/frontend/src/features/rooms/livekit/components/controls/ReactionsToggle.tsx
index de299603..ee128d41 100644
--- a/src/frontend/src/features/rooms/livekit/components/controls/ReactionsToggle.tsx
+++ b/src/frontend/src/features/rooms/livekit/components/controls/ReactionsToggle.tsx
@@ -12,6 +12,7 @@ import {
} from '@/features/rooms/livekit/components/ReactionPortal'
import { Toolbar as RACToolbar } from 'react-aria-components'
import { Participant } from 'livekit-client'
+import useRateLimiter from '@/hooks/useRateLimiter'
// eslint-disable-next-line react-refresh/only-export-components
export const EMOJIS = ['๐Ÿ‘', '๐Ÿ‘Ž', '๐Ÿ‘', 'โค๏ธ', '๐Ÿ˜‚', '๐Ÿ˜ฎ', '๐ŸŽ‰']
@@ -56,6 +57,12 @@ export const ReactionsToggle = () => {
}, ANIMATION_DURATION)
}
+ const debouncedSendReaction = useRateLimiter({
+ callback: sendReaction,
+ maxCalls: 10,
+ windowMs: 1000,
+ })
+
// Custom animation implementation for the emoji toolbar
// Could not use a menu and its animation, because a menu would make the toolbar inaccessible by keyboard
// animation isn't perfect
@@ -127,7 +134,7 @@ export const ReactionsToggle = () => {
{EMOJIS.map((emoji, index) => (
<Button
key={index}
- onPress={() => sendReaction(emoji)}
+ onPress={() => debouncedSendReaction(emoji)}
aria-label={t('send', { emoji })}
variant="primaryTextDark"
size="sm"