Writing an Nginx authentication module in Lua and Go
stavros.io
stavros.io
The timing attack (i.e. memcmp) would happen at the string interning step; which cannot be avoided: but as a lua_State persists longer than a single request, I'm unsure if a timing attack here is plausible.
edit: someone answered this in a sibling post with 'yes'.
This means strings can never be modified => a new one is created.
The down side is that string modification (including appending) in a loop is expensive.
local string_buffer = {}
while condition() do
table.insert(string_buffer, getString())
end
local string = table.concat(string_buffer)http://golang.org/pkg/io/#WriteString
vs
http://php.net/fwrite and http://msdn.microsoft.com/en-us/library/ms143376.aspx
[1] Edit: I'm aware that learning via documentation is probably not the right way to do it, but it's part of the learning process and thus, good documentation is important.
We've recently done a refactor of a lot of complex load balancer rules into lua + redis. It really is a lot more maintainable.
While it is more maintainable, don't let the illusion fool you - the complexity is still there. The solution may be quicker, but you still had to write code for the solution. It's just different code - and in a different place - from where you'd otherwise put it.
In our case, it made sense - the logic was all already in the load balancer, it was just a lot more scattered. In other cases - such as splitting what is truly application logic between your LB and your application - it may lead to more headache than it's worth in exchange for a few ms of performance improvement.
(I'll likely be writing this thought up in more detail in the near future.)
here's a use case: you want to proxy request cookies from your application into 2 cookies (session/persistent), but you don't want to rewrite the legacy app. lua does a great job with request/response manipulation.
Also, the if c1 ~= c2 branch is obviously not constant-time, but in practice it’s close enough that it won’t matter for our case. I’d prefer XORing the two strings together and seeing if the result is 0, but Lua doesn’t seem to include a bitwise XOR operator. If I’m wrong on this, I would appreciate a correction.
LuaJIT provides bitwise operators out of the box [1], and the creator also provides an extension for regular lua [2].So not much different.