FEATURE: improve honeypot and challenge logic

This feature amends it so instead of using one challenge and honeypot
statically per site we have a rotating honeypot and challenge value which
changes every hour.

This means you must grab a fresh copy of honeypot and challenge value once
an hour or account registration will be rejected.

We also now cycle the value of the challenge when after successful account
registration forcing an extra call to hp.json between account registrations

Client has been made aware of these changes.

Additionally this contains a JavaScript workaround for:
https://bugs.chromium.org/p/chromium/issues/detail?id=987293

This is client side code that is specific to Chrome user agent and swaps
a PASSWORD type honeypot with a TEXT type honeypot.
This commit is contained in:
Sam Saffron
2019-10-16 16:53:31 +11:00
parent 645faa847b
commit d5d8db7fa8
5 changed files with 198 additions and 98 deletions

View File

@ -6,15 +6,36 @@ class SecureSession
@prefix = prefix
end
def self.expiry
@expiry ||= 1.hour.to_i
end
def self.expiry=(val)
@expiry = val
end
def set(key, val, expires: nil)
expires ||= SecureSession.expiry
$redis.setex(prefixed_key(key), SecureSession.expiry.to_i, val.to_s)
true
end
def [](key)
$redis.get("#{@prefix}#{key}")
$redis.get(prefixed_key(key))
end
def []=(key, val)
if val == nil
$redis.del("#{@prefix}#{key}")
$redis.del(prefixed_key(key))
else
$redis.setex("#{@prefix}#{key}", 1.hour, val.to_s)
$redis.setex(prefixed_key(key), SecureSession.expiry.to_i, val.to_s)
end
val
end
private
def prefixed_key(key)
"#{@prefix}#{key}"
end
end