mirror of
https://github.com/TwiN/gatus.git
synced 2025-06-20 09:47:55 +02:00
fix(api): Escape endpoint key in URL (#1114)
ISSUE #1100 | Fix bug with URL encoding Co-authored-by: Семисохин Андрей <semisohin@kinoplan.ru> Co-authored-by: TwiN <twin@linux.com>
This commit is contained in:
parent
c449738844
commit
0a9f5d8838
21
api/badge.go
21
api/badge.go
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -53,7 +54,10 @@ func UptimeBadge(c *fiber.Ctx) error {
|
|||||||
default:
|
default:
|
||||||
return c.Status(400).SendString("Durations supported: 30d, 7d, 24h, 1h")
|
return c.Status(400).SendString("Durations supported: 30d, 7d, 24h, 1h")
|
||||||
}
|
}
|
||||||
key := c.Params("key")
|
key, err := url.QueryUnescape(c.Params("key"))
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(400).SendString("invalid key encoding")
|
||||||
|
}
|
||||||
uptime, err := store.Get().GetUptimeByKey(key, from, time.Now())
|
uptime, err := store.Get().GetUptimeByKey(key, from, time.Now())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, common.ErrEndpointNotFound) {
|
if errors.Is(err, common.ErrEndpointNotFound) {
|
||||||
@ -88,7 +92,10 @@ func ResponseTimeBadge(cfg *config.Config) fiber.Handler {
|
|||||||
default:
|
default:
|
||||||
return c.Status(400).SendString("Durations supported: 30d, 7d, 24h, 1h")
|
return c.Status(400).SendString("Durations supported: 30d, 7d, 24h, 1h")
|
||||||
}
|
}
|
||||||
key := c.Params("key")
|
key, err := url.QueryUnescape(c.Params("key"))
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(400).SendString("invalid key encoding")
|
||||||
|
}
|
||||||
averageResponseTime, err := store.Get().GetAverageResponseTimeByKey(key, from, time.Now())
|
averageResponseTime, err := store.Get().GetAverageResponseTimeByKey(key, from, time.Now())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, common.ErrEndpointNotFound) {
|
if errors.Is(err, common.ErrEndpointNotFound) {
|
||||||
@ -107,7 +114,10 @@ func ResponseTimeBadge(cfg *config.Config) fiber.Handler {
|
|||||||
|
|
||||||
// HealthBadge handles the automatic generation of badge based on the group name and endpoint name passed.
|
// HealthBadge handles the automatic generation of badge based on the group name and endpoint name passed.
|
||||||
func HealthBadge(c *fiber.Ctx) error {
|
func HealthBadge(c *fiber.Ctx) error {
|
||||||
key := c.Params("key")
|
key, err := url.QueryUnescape(c.Params("key"))
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(400).SendString("invalid key encoding")
|
||||||
|
}
|
||||||
pagingConfig := paging.NewEndpointStatusParams()
|
pagingConfig := paging.NewEndpointStatusParams()
|
||||||
status, err := store.Get().GetEndpointStatusByKey(key, pagingConfig.WithResults(1, 1))
|
status, err := store.Get().GetEndpointStatusByKey(key, pagingConfig.WithResults(1, 1))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -133,7 +143,10 @@ func HealthBadge(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func HealthBadgeShields(c *fiber.Ctx) error {
|
func HealthBadgeShields(c *fiber.Ctx) error {
|
||||||
key := c.Params("key")
|
key, err := url.QueryUnescape(c.Params("key"))
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(400).SendString("invalid key encoding")
|
||||||
|
}
|
||||||
pagingConfig := paging.NewEndpointStatusParams()
|
pagingConfig := paging.NewEndpointStatusParams()
|
||||||
status, err := store.Get().GetEndpointStatusByKey(key, pagingConfig.WithResults(1, 1))
|
status, err := store.Get().GetEndpointStatusByKey(key, pagingConfig.WithResults(1, 1))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -45,7 +46,11 @@ func ResponseTimeChart(c *fiber.Ctx) error {
|
|||||||
default:
|
default:
|
||||||
return c.Status(400).SendString("Durations supported: 30d, 7d, 24h")
|
return c.Status(400).SendString("Durations supported: 30d, 7d, 24h")
|
||||||
}
|
}
|
||||||
hourlyAverageResponseTime, err := store.Get().GetHourlyAverageResponseTimeByKey(c.Params("key"), from, time.Now())
|
key, err := url.QueryUnescape(c.Params("key"))
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(400).SendString("invalid key encoding")
|
||||||
|
}
|
||||||
|
hourlyAverageResponseTime, err := store.Get().GetHourlyAverageResponseTimeByKey(key, from, time.Now())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, common.ErrEndpointNotFound) {
|
if errors.Is(err, common.ErrEndpointNotFound) {
|
||||||
return c.Status(404).SendString(err.Error())
|
return c.Status(404).SendString(err.Error())
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
|
||||||
"github.com/TwiN/gatus/v5/client"
|
"github.com/TwiN/gatus/v5/client"
|
||||||
"github.com/TwiN/gatus/v5/config"
|
"github.com/TwiN/gatus/v5/config"
|
||||||
@ -86,7 +87,12 @@ func getEndpointStatusesFromRemoteInstances(remoteConfig *remote.Config) ([]*end
|
|||||||
func EndpointStatus(cfg *config.Config) fiber.Handler {
|
func EndpointStatus(cfg *config.Config) fiber.Handler {
|
||||||
return func(c *fiber.Ctx) error {
|
return func(c *fiber.Ctx) error {
|
||||||
page, pageSize := extractPageAndPageSizeFromRequest(c, cfg.Storage.MaximumNumberOfResults)
|
page, pageSize := extractPageAndPageSizeFromRequest(c, cfg.Storage.MaximumNumberOfResults)
|
||||||
endpointStatus, err := store.Get().GetEndpointStatusByKey(c.Params("key"), paging.NewEndpointStatusParams().WithResults(page, pageSize).WithEvents(1, cfg.Storage.MaximumNumberOfEvents))
|
key, err := url.QueryUnescape(c.Params("key"))
|
||||||
|
if err != nil {
|
||||||
|
logr.Errorf("[api.EndpointStatus] Failed to decode key: %s", err.Error())
|
||||||
|
return c.Status(400).SendString("invalid key encoding")
|
||||||
|
}
|
||||||
|
endpointStatus, err := store.Get().GetEndpointStatusByKey(key, paging.NewEndpointStatusParams().WithResults(page, pageSize).WithEvents(1, cfg.Storage.MaximumNumberOfEvents))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, common.ErrEndpointNotFound) {
|
if errors.Is(err, common.ErrEndpointNotFound) {
|
||||||
return c.Status(404).SendString(err.Error())
|
return c.Status(404).SendString(err.Error())
|
||||||
@ -95,7 +101,7 @@ func EndpointStatus(cfg *config.Config) fiber.Handler {
|
|||||||
return c.Status(500).SendString(err.Error())
|
return c.Status(500).SendString(err.Error())
|
||||||
}
|
}
|
||||||
if endpointStatus == nil { // XXX: is this check necessary?
|
if endpointStatus == nil { // XXX: is this check necessary?
|
||||||
logr.Errorf("[api.EndpointStatus] Endpoint with key=%s not found", c.Params("key"))
|
logr.Errorf("[api.EndpointStatus] Endpoint with key=%s not found", key)
|
||||||
return c.Status(404).SendString("not found")
|
return c.Status(404).SendString("not found")
|
||||||
}
|
}
|
||||||
output, err := json.Marshal(endpointStatus)
|
output, err := json.Marshal(endpointStatus)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user