Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions caddy/Caddyfile.prod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ oullin.io {
format json
}

route /api/generate-signature/* {
@allowed {
# Allow requests only from the VPS itself (localhost).
ip_range 127.0.0.1 ::1
}

# If the remote IP is not in the allowed range, abort the connection.
abort not @allowed
}

# API handler.
# - Reverse-proxy all requests to the Go API, forwarding Host + auth headers.
# - to: Tell Caddy which upstream to send to.
Expand Down
20 changes: 0 additions & 20 deletions pkg/middleware/public_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ func (p PublicMiddleware) Handle(next http.ApiHandler) http.ApiHandler {
return mwguards.RateLimitedError("Too many requests", "Too many requests for key: "+limiterKey)
}

if err := p.HasInvalidIP(r); err != nil {
p.rateLimiter.Fail(limiterKey)

return err
}

vt := mwguards.NewValidTimestamp(ts, p.now)
if err := vt.Validate(p.clockSkew, p.disallowFuture); err != nil {
p.rateLimiter.Fail(limiterKey)
Expand All @@ -89,20 +83,6 @@ func (p PublicMiddleware) Handle(next http.ApiHandler) http.ApiHandler {
}
}

func (p PublicMiddleware) HasInvalidIP(r *baseHttp.Request) *http.ApiError {
ip := portal.ParseClientIP(r)

if ip == "" {
return mwguards.InvalidRequestError("Clients IPs are required to access this endpoint", "")
}

if p.isProduction && ip != p.allowedIP {
return mwguards.InvalidRequestError("The given IP is not allowed", "unauthorised ip: "+ip)
}

return nil
}

func (p PublicMiddleware) GuardDependencies() *http.ApiError {
missing := []string{}

Expand Down
Loading