Commit 89dd67c
committed
fix(auth): move the OTP send guard to hooks.before (admission control)
Found dogfooding the live flow: better-auth's /phone-number/send-otp stores
the fresh code BEFORE invoking sendOTP, so a cooldown rejection thrown from
the callback still rotated - and thereby invalidated - the previously
delivered code. A user hitting resend during the cooldown (or an attacker
spamming the endpoint) voided the valid OTP every time.
The per-number cooldown/hourly-cap check now runs in the hooks.before
middleware (assertPhoneOtpSendAllowed) for /phone-number/send-otp and
/phone-number/request-password-reset - rejected requests never reach the
endpoint handler, so the stored code survives. The sendOTP callback only
delivers. Behaviour verified end-to-end against a live server.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013LXUXU66dBaP3SSG4ZVtuH1 parent 44009d7 commit 89dd67c
2 files changed
Lines changed: 72 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1143 | 1143 | | |
1144 | 1144 | | |
1145 | 1145 | | |
1146 | | - | |
| 1146 | + | |
1147 | 1147 | | |
1148 | 1148 | | |
1149 | 1149 | | |
1150 | 1150 | | |
1151 | | - | |
1152 | | - | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
1153 | 1154 | | |
1154 | | - | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
1155 | 1163 | | |
1156 | 1164 | | |
1157 | | - | |
1158 | | - | |
1159 | | - | |
1160 | | - | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
1161 | 1168 | | |
1162 | | - | |
1163 | | - | |
1164 | | - | |
1165 | | - | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
1166 | 1172 | | |
1167 | 1173 | | |
1168 | 1174 | | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
1169 | 1182 | | |
1170 | 1183 | | |
1171 | 1184 | | |
| |||
1175 | 1188 | | |
1176 | 1189 | | |
1177 | 1190 | | |
1178 | | - | |
1179 | | - | |
1180 | | - | |
1181 | | - | |
1182 | | - | |
1183 | | - | |
1184 | | - | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
1185 | 1196 | | |
1186 | 1197 | | |
1187 | 1198 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
818 | 818 | | |
819 | 819 | | |
820 | 820 | | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
821 | 838 | | |
822 | 839 | | |
823 | 840 | | |
| |||
2084 | 2101 | | |
2085 | 2102 | | |
2086 | 2103 | | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
| 2114 | + | |
| 2115 | + | |
| 2116 | + | |
| 2117 | + | |
| 2118 | + | |
| 2119 | + | |
| 2120 | + | |
| 2121 | + | |
| 2122 | + | |
2087 | 2123 | | |
2088 | 2124 | | |
2089 | 2125 | | |
2090 | 2126 | | |
2091 | 2127 | | |
2092 | | - | |
2093 | | - | |
2094 | | - | |
2095 | | - | |
| 2128 | + | |
| 2129 | + | |
| 2130 | + | |
| 2131 | + | |
| 2132 | + | |
| 2133 | + | |
2096 | 2134 | | |
2097 | 2135 | | |
2098 | 2136 | | |
| |||
2108 | 2146 | | |
2109 | 2147 | | |
2110 | 2148 | | |
2111 | | - | |
2112 | | - | |
2113 | | - | |
2114 | | - | |
2115 | | - | |
2116 | | - | |
2117 | | - | |
2118 | 2149 | | |
2119 | 2150 | | |
2120 | 2151 | | |
| |||
0 commit comments