Skip to content

Commit

Permalink
fix: unescape url in registry sync and delete (#1571)
Browse files Browse the repository at this point in the history
fix: unescape url in registry snc and delete
  • Loading branch information
Harshvardhan Karn authored Sep 14, 2023
1 parent 929d0dc commit d09bdb6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 12 additions & 2 deletions deepfence_server/handler/container_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,12 @@ func (h *Handler) AddGoogleContainerRegistry(w http.ResponseWriter, r *http.Requ
}

func (h *Handler) DeleteRegistry(w http.ResponseWriter, r *http.Request) {
id := chi.URLParam(r, "registry_id")
id, err := utils.URLDecode(chi.URLParam(r, "registry_id"))
if err != nil {
log.Error().Msgf("%v", err)
h.respondError(&BadDecoding{err}, w)
return
}

pgIds, err := model.GetRegistryPgIds(r.Context(), id)
if err != nil {
Expand Down Expand Up @@ -497,7 +502,12 @@ func (h *Handler) DeleteRegistry(w http.ResponseWriter, r *http.Request) {
}

func (h *Handler) RefreshRegistry(w http.ResponseWriter, r *http.Request) {
id := chi.URLParam(r, "registry_id")
id, err := utils.URLDecode(chi.URLParam(r, "registry_id"))
if err != nil {
log.Error().Msgf("%v", err)
h.respondError(&BadDecoding{err}, w)
return
}

pgIds, err := model.GetRegistryPgIds(r.Context(), id)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions deepfence_utils/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,10 @@ func URLEncode(s string) string {
return url.QueryEscape(s)
}

func URLDecode(s string) (string, error) {
return url.QueryUnescape(s)
}

func GetErrorRedirectUrl(consoleUrl, errorMessage string) string {
return consoleUrl + "/?errorMessage=" + URLEncode(errorMessage)
}
Expand Down

0 comments on commit d09bdb6

Please sign in to comment.