ash_authentication brute-force weakness
Description
Improper Restriction of Excessive Authentication Attempts vulnerability in team-alembic ash_authentication allows an unauthenticated attacker to guess passwords and one-time passwords without limit, and to trigger password-reset and magic-link emails without limit, via sign-in and request actions defined on the user resource.
The password, magic link and OTP strategies enforce brute_force_strategy by adding a preparation to the actions they generate. That preparation is AshAuthentication.AddOn.AuditLog.IdentityBruteForcePreparation, AshAuthentication.AddOn.AuditLog.BruteForcePreparation, or the module given in {:preparation, module}. When the resource defines one of those actions itself, the strategy uses it as written, and nothing checked that it carried the preparation, so the setting compiled and applied no limit.
The generators produce exactly this. mix ash_authentication.install writes sign_in_with_password, request_password_reset_token and request_magic_link on the resource. mix ash_authentication.upgrade then adds brute_force_strategy {:audit_log, :audit_log} to those strategies and reports that brute-force protection has been added. mix ash_authentication.add_strategy.otp writes request_otp and sign_in_with_otp without the preparations while configuring brute_force_strategy {:audit_log, :audit_log}, so a one-time password can be guessed without limit for as long as it is valid.
Configurations
Reachable when a password, magic link or OTP strategy sets brute_force_strategy, and any of its protected actions is defined on the resource without the matching preparation. The protected actions are password sign-in, password reset request, magic link request, OTP sign-in and OTP request. Resources set up by the generators above are affected. Actions the strategy generates itself carry the preparation and are not affected, and neither is the OTP strategy's brute_force_strategy :rate_limit, which is checked per action against ash_rate_limiter rules. OTP with registration_enabled? true and brute_force_strategy {:preparation, module} is also affected: its sign-in is a create action, which preparations do not run on, so sign-in attempts were not limited.
Workarounds
Add the preparation to each protected action defined on the resource, or delete the action so the strategy generates it:
# password sign-in, password reset request, magic link request, OTP request
prepare {AshAuthentication.AddOn.AuditLog.IdentityBruteForcePreparation,
action_name: :sign_in_with_password}
# OTP sign-in (a read action)
prepare {AshAuthentication.AddOn.AuditLog.BruteForcePreparation,
action_name: :sign_in_with_otp}With brute_force_strategy {:preparation, MyModule}, add prepare MyModule instead. For OTP with registration_enabled? true, switch to brute_force_strategy :rate_limit.
The audit log batches writes by default, so a failed attempt can be counted up to ten seconds late. Setting write_batching enabled? false on the audit log resource closes that window.
Patches
Fixed in ash_authentication 5.0.0-rc.16. A brute_force_strategy whose protected actions lack its preparation is now a compile error that names each action and the prepare line to add, and mix ash_authentication.add_strategy.otp writes the preparations. For OTP with registration_enabled? true, {:preparation, module} is now refused at compile time as {:audit_log, _} already was, so :rate_limit is the only accepted strategy in that mode. Applications that relied on the old behaviour will fail to compile until they add the preparation or switch to :rate_limit.