Skip to content

Commit

Permalink
fix: chaoshub handler path injection
Browse files Browse the repository at this point in the history
Signed-off-by: Jaeyeon Park <[email protected]>
  • Loading branch information
moggaa committed Aug 4, 2024
1 parent 1f3cf95 commit 67fadc1
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions chaoscenter/graphql/server/pkg/chaoshub/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,21 @@ func ChaosHubIconHandler() gin.HandlerFunc {
responseStatusCode int
)

projectID := sanitize.PathName(c.Param("projectId"))
hubName := sanitize.PathName(c.Param("hubName"))
chartName := sanitize.PathName(c.Param("chartName"))
iconName := sanitize.PathName(c.Param("iconName"))

if strings.ToLower(c.Param("chartName")) == "predefined" {
img, err = os.Open(utils.Config.CustomChaosHubPath + c.Param("projectId") + "/" + c.Param("hubName") + "/experiments/icons/" + c.Param("iconName"))
img, err = os.Open(utils.Config.CustomChaosHubPath + projectID + "/" + hubName + "/experiments/icons/" + iconName)
responseStatusCode = http.StatusOK
if err != nil {
responseStatusCode = http.StatusInternalServerError
log.WithError(err).Error("icon cannot be fetched")
fmt.Fprint(c.Writer, "icon cannot be fetched, err : "+err.Error())
}
} else {
img, err = os.Open(utils.Config.CustomChaosHubPath + c.Param("projectId") + "/" + c.Param("hubName") + "/faults/" + c.Param("chartName") + "/icons/" + c.Param("iconName"))
img, err = os.Open(utils.Config.CustomChaosHubPath + projectID + "/" + hubName + "/faults/" + chartName + "/icons/" + iconName)
responseStatusCode = http.StatusOK
if err != nil {
responseStatusCode = http.StatusInternalServerError
Expand All @@ -354,16 +359,20 @@ func DefaultChaosHubIconHandler() gin.HandlerFunc {
responseStatusCode int
)

hubName := sanitize.PathName(c.Param("hubName"))
chartName := sanitize.PathName(c.Param("chartName"))
iconName := sanitize.PathName(c.Param("iconName"))

if strings.ToLower(c.Param("chartName")) == "predefined" {
img, err = os.Open(utils.Config.DefaultChaosHubPath + c.Param("hubName") + "/experiments/icons/" + c.Param("iconName"))
img, err = os.Open(utils.Config.DefaultChaosHubPath + hubName + "/experiments/icons/" + iconName)
responseStatusCode = http.StatusOK
if err != nil {
responseStatusCode = http.StatusInternalServerError
log.WithError(err).Error("icon cannot be fetched")
fmt.Fprint(c.Writer, "icon cannot be fetched, err : "+err.Error())
}
} else {
img, err = os.Open(utils.Config.DefaultChaosHubPath + c.Param("hubName") + "/faults/" + c.Param("chartName") + "/icons/" + c.Param("iconName"))
img, err = os.Open(utils.Config.DefaultChaosHubPath + hubName + "/faults/" + chartName + "/icons/" + iconName)
responseStatusCode = http.StatusOK
if err != nil {
responseStatusCode = http.StatusInternalServerError
Expand Down

0 comments on commit 67fadc1

Please sign in to comment.