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 61b02d3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 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 Down

0 comments on commit 61b02d3

Please sign in to comment.