Repository navigation
Commit 4cd7685
Fix 500 on attendance_cleanup_rule "run now": scope job to the rule's own userId (#157)
* Fix 500 on attendance_cleanup_rule 'run now': scope job to the rule's own userId
Production error:
QueryFailedError: Field 'user_id' doesn't have a default value
INSERT INTO `jobs`(..., `user_id`, ...) VALUES (..., DEFAULT, ...)
runNow used getUserIdFromUser(req.auth) as the enqueued job's userId.
That's wrong for this action: CrudAuthWithPermissionsFilter grants
admins AND anyone with the attendanceCleanupRules permission full
visibility (not just their own rows), so a requester can select rules
owned by a different user - and for admin specifically,
getUserIdFromUser always returns undefined (id -1 is a sentinel, not a
real tenant), which is what produced the undefined user_id insert.
Fix: load the selected rules and derive the job's userId from each
rule's own userId, enqueuing one job per distinct owner so a
multi-tenant selection is scoped correctly rather than crashing or
silently misattributing the sweep.
Reproduced the exact error against a real MySQL jobs table
(enqueue(undefined, ...)) and confirmed the fix (enqueue(38, ...))
succeeds.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011dEYULADLgGNfZ4nv6gz8s
* Close cross-tenant data exposure: use standard CrudAuthFilter, not permission-based full visibility
Addresses Copilot review comment on this PR, and explicit user direction:
CrudAuthWithPermissionsFilter granted ADMIN_FILTER (full visibility, not
just-your-own-rows) to anyone with the attendanceCleanupRules permission -
and doAction's runNow is a custom route that bypasses @dataui/crud's normal
auth-filtered query building entirely, so it never consulted that filter
in the first place. Together, any authenticated user could pass arbitrary
rule ids to runNow and have jobs enqueued under other tenants' identities.
Fix:
- crudAuth is now the standard CrudAuthFilter (admin sees all, everyone
else sees only their own rows) - same as most other entities. The
attendanceCleanupRules permission remains a client-side visibility gate
only; it no longer grants any server-side data access.
- runNow explicitly applies crudAuth.filter(req.auth) to its id lookup,
since this custom route doesn't go through the filtered query path -
a non-owned id in the selection just doesn't resolve, instead of being
trusted from the request.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011dEYULADLgGNfZ4nv6gz8s
* Use the new BaseEntityService.getManyByIds for runNow's id lookup
Simplifies the previous manual crudAuth.filter(req.auth) + raw find()
into a call to the new shared helper (nra-server#43), which applies the
same auth filtering through the real query-building path instead of
duplicating it per action.
bump server/shared to 24975d1 to pick up getManyByIds.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011dEYULADLgGNfZ4nv6gz8s
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent e61595e commit 4cd7685
3 files changed
Lines changed: 77 additions & 25 deletions
File tree
- server
- src/entity-modules
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | | - | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
37 | 34 | | |
38 | 35 | | |
39 | 36 | | |
| |||
54 | 51 | | |
55 | 52 | | |
56 | 53 | | |
57 | | - | |
58 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
59 | 58 | | |
60 | | - | |
61 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
62 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
63 | 73 | | |
64 | 74 | | |
65 | 75 | | |
66 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
67 | 79 | | |
68 | 80 | | |
69 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
70 | 108 | | |
71 | 109 | | |
72 | 110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
| 3 | + | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
| |||
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
25 | | - | |
26 | 24 | | |
27 | | - | |
28 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
29 | 40 | | |
30 | 41 | | |
31 | 42 | | |
| |||
35 | 46 | | |
36 | 47 | | |
37 | 48 | | |
38 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
39 | 53 | | |
40 | 54 | | |
41 | 55 | | |
| |||
0 commit comments