You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Unique constraint ensures one response per user per poll
112
112
- Auto-sets `submitted_at` timestamp via trigger
113
113
114
+
### Anonymous Response Behavior
115
+
116
+
**⚠️ CRITICAL: The UNIQUE constraint does not prevent duplicate anonymous responses.**
117
+
118
+
The constraint `UNIQUE (live_poll_id, public_profile_id)` enforces one response per authenticated user, but due to PostgreSQL's NULL handling, **anonymous users (where `public_profile_id` is NULL) can submit unlimited responses to the same poll**.
119
+
120
+
#### Current Behavior by User Type:
121
+
122
+
| User Type | Deduplication | Behavior |
123
+
|-----------|--------------|----------|
124
+
|**Authenticated** (`require_login = true`) | ✅ Enforced by UNIQUE constraint | One response per user per poll |
In PostgreSQL, NULL values in UNIQUE constraints are considered distinct from each other. Multiple rows with `(live_poll_id, NULL)` are all valid and don't violate the constraint.
129
+
130
+
#### Current Mitigations:
131
+
-**None at application level**: No client-side tracking, rate limiting, or session-based restrictions
132
+
-**No server-side deduplication**: Anonymous responses go directly to the database without checks
133
+
134
+
#### Design Decision:
135
+
Anonymous responses are intentionally allowed (see RLS policy comments), but **unlimited anonymous responses appear to be an unintended consequence** rather than a deliberate feature.
136
+
137
+
#### Potential Solutions (if limiting is desired):
138
+
139
+
1.**Require Login for Sensitive Polls**
140
+
- Set `require_login = true` for polls where single-response is critical
0 commit comments