mirror of
https://github.com/joohoi/acme-dns.git
synced 2025-07-13 17:27:51 +07:00
Added subdomain check to auth middleware
This commit is contained in:
13
api.go
13
api.go
@ -22,14 +22,21 @@ func PostHandlerMap() map[string]func(*iris.Context) {
|
|||||||
func (a AuthMiddleware) Serve(ctx *iris.Context) {
|
func (a AuthMiddleware) Serve(ctx *iris.Context) {
|
||||||
usernameStr := ctx.RequestHeader("X-Api-User")
|
usernameStr := ctx.RequestHeader("X-Api-User")
|
||||||
password := ctx.RequestHeader("X-Api-Key")
|
password := ctx.RequestHeader("X-Api-Key")
|
||||||
|
postData := ACMETxt{}
|
||||||
|
|
||||||
username, err := GetValidUsername(usernameStr)
|
username, err := GetValidUsername(usernameStr)
|
||||||
if err == nil && ValidKey(password) {
|
if err == nil && ValidKey(password) {
|
||||||
au, err := DB.GetByUsername(username)
|
au, err := DB.GetByUsername(username)
|
||||||
if err == nil && CorrectPassword(password, au.Password) {
|
if err == nil && CorrectPassword(password, au.Password) {
|
||||||
log.Debugf("Accepted authentication from [%s]", usernameStr)
|
// Password ok
|
||||||
ctx.Next()
|
if err := ctx.ReadJSON(&postData); err != nil {
|
||||||
return
|
// Check that the subdomain belongs to the user
|
||||||
|
if au.Subdomain == postData.Subdomain {
|
||||||
|
log.Debugf("Accepted authentication from [%s]", usernameStr)
|
||||||
|
ctx.Next()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// To protect against timed side channel (never gonna give you up)
|
// To protect against timed side channel (never gonna give you up)
|
||||||
CorrectPassword(password, "$2a$10$8JEFVNYYhLoBysjAxe2yBuXrkDojBQBkVpXEQgyQyjn43SvJ4vL36")
|
CorrectPassword(password, "$2a$10$8JEFVNYYhLoBysjAxe2yBuXrkDojBQBkVpXEQgyQyjn43SvJ4vL36")
|
||||||
|
Reference in New Issue
Block a user