Occasionally I want to save an article from my feed reader to Espial to read it later. The feed reader I use (Miniflux) provides integrations with different such services, and I am trying to add an Espial integration as well. Unfortunately, Espial uses cookie-based authentication throughout the app and as such makes heavy use of sessions, making it hard to consume by third-party services. This PR adds an alternative API key auth mechanism, to be allowed for selectively for specific routes. For such routes, an authorization header of the form Authorization: ApiKey <API-KEY> could be used to gain access to the resource. API keys are managed through the usual migration utility with two new commands: createapikey and deleteapikey.
API keys are generated by reading 32 random bytes and encoding it as base64
Keys are stored in database in hashed form (SHA-256)
The hash is unsalted, since we want to be able to lookup a user by a given API key (I don't think this poses to be a problem since the key itself is random and pretty long to be vulnerable to brute forcing, though alternatives could be discussed)
CSRF middleware is disabled if an authorization header is provided and the requested route allows for API key auth
I think the implementation doesn't expose any vulnerabilities, though I am not too familiar with the Yesod way of doing things and security isn't my strongest suite, so I would appreciate feedback regarding these choices.
Motivation:
Occasionally I want to save an article from my feed reader to Espial to read it later. The feed reader I use (Miniflux) provides integrations with different such services, and I am trying to add an Espial integration as well. Unfortunately, Espial uses cookie-based authentication throughout the app and as such makes heavy use of sessions, making it hard to consume by third-party services. This PR adds an alternative API key auth mechanism, to be allowed for selectively for specific routes. For such routes, an authorization header of the form
Authorization: ApiKey <API-KEY>
could be used to gain access to the resource. API keys are managed through the usual migration utility with two new commands:createapikey
anddeleteapikey
.For example:
Implementation details:
I think the implementation doesn't expose any vulnerabilities, though I am not too familiar with the Yesod way of doing things and security isn't my strongest suite, so I would appreciate feedback regarding these choices.