Commit 7742c9c
committed
fix(session,security): close 11 correctness and hardening gaps
CRITICAL
- Grace period for first request after login: JWT-verify wrapper now
accepts a freshly-issued JWT within a configurable `sessionCreationGraceMs`
window (default 5s) even if the session-create DB write has not yet
propagated. Closes the race where strictSessionEnforcement blocked the
very first authenticated request.
- Cleanup no longer leaves sessions reactivatable. Inactivity cleanup now
sets terminatedManually=true, and the JWT-verify wrapper refuses to
reactivate sessions that have been idle longer than inactivityTimeout.
The idle-logout feature actually works now.
- SESSION_ENCRYPTION_KEY is mandatory in production (boot self-test in
bootstrap). Fallback to APP_KEYS is kept only for non-production, with
a one-time WARN; this prevents APP_KEYS rotation from silently bricking
every stored session.
HIGH
- mountRefreshTokenInterceptor now documents that users-permissions ships
no /api/auth/refresh by default and the middleware is a passthrough
until a refresh plugin is installed.
- ensureContentApiPermissions migrated from the deprecated
strapi.entityService to strapi.documents (Strapi v5 API).
- extractBearerToken token-length range widened from 10..4096 to 40..8192
to accommodate modern JWTs carrying user-context claims (magic-link).
- session.touch() now coalesces concurrent callers through an in-memory
per-session stamp so two parallel requests cannot both skip the
rate-limit and issue duplicate UPDATEs.
MEDIUM
- Missing JWT service is now logged at ERROR (not WARN) because session
revocation silently stops enforcing — ops needs to see it.
- register.js afterUpdate hook checks params.data.blocked to only scan
sessions when THIS update set blocked=true, not on every unrelated
user update.
- Per-caller rate-limit middleware (plugin::magic-sessionmanager.rate-limit)
mounted on all content-api routes: 10/min for writes (logout, terminate),
120/min for reads.
- cleanupInactiveSessions gained a useDbDirect option (exposed via the
cleanupUseDbDirect setting) for a single-statement SQL UPDATE path on
installations that outgrow the 50k Document-Service scan cap.1 parent 34f64a4 commit 7742c9c
9 files changed
Lines changed: 393 additions & 66 deletions
File tree
- server/src
- middlewares
- routes
- services
- utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
56 | 67 | | |
57 | 68 | | |
58 | 69 | | |
| |||
109 | 120 | | |
110 | 121 | | |
111 | 122 | | |
112 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
113 | 131 | | |
114 | 132 | | |
115 | 133 | | |
116 | 134 | | |
117 | 135 | | |
118 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
119 | 140 | | |
120 | 141 | | |
121 | 142 | | |
| |||
649 | 670 | | |
650 | 671 | | |
651 | 672 | | |
652 | | - | |
653 | | - | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
654 | 690 | | |
655 | 691 | | |
656 | 692 | | |
| |||
761 | 797 | | |
762 | 798 | | |
763 | 799 | | |
764 | | - | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
765 | 805 | | |
| 806 | + | |
766 | 807 | | |
767 | 808 | | |
768 | 809 | | |
| |||
782 | 823 | | |
783 | 824 | | |
784 | 825 | | |
785 | | - | |
| 826 | + | |
786 | 827 | | |
787 | 828 | | |
788 | 829 | | |
789 | 830 | | |
| 831 | + | |
| 832 | + | |
790 | 833 | | |
791 | 834 | | |
792 | 835 | | |
| |||
799 | 842 | | |
800 | 843 | | |
801 | 844 | | |
802 | | - | |
| 845 | + | |
803 | 846 | | |
804 | 847 | | |
805 | 848 | | |
| |||
935 | 978 | | |
936 | 979 | | |
937 | 980 | | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
938 | 985 | | |
939 | | - | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
940 | 990 | | |
941 | 991 | | |
942 | 992 | | |
943 | 993 | | |
944 | 994 | | |
945 | 995 | | |
946 | | - | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
947 | 1000 | | |
948 | 1001 | | |
949 | 1002 | | |
| |||
972 | 1025 | | |
973 | 1026 | | |
974 | 1027 | | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
975 | 1039 | | |
976 | 1040 | | |
977 | 1041 | | |
| |||
1030 | 1094 | | |
1031 | 1095 | | |
1032 | 1096 | | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
1033 | 1120 | | |
1034 | 1121 | | |
1035 | 1122 | | |
| |||
1041 | 1128 | | |
1042 | 1129 | | |
1043 | 1130 | | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
1044 | 1147 | | |
1045 | 1148 | | |
1046 | 1149 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
| 62 | + | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
65 | 71 | | |
66 | 72 | | |
67 | 73 | | |
| |||
0 commit comments