Skip to content
Merged
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
13 changes: 10 additions & 3 deletions pkg/handlers/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ func (h Handlers) Download(rw http.ResponseWriter, req *http.Request) {
attributes = append(attributes, attribute.String("module.sum", sum))

ph, errH := h.store.GetHashByName(ctx, pluginName, version)
if errH != nil {

switch {
case errH != nil:
span.RecordError(errH)

if !errors.As(errH, &db.NotFoundError{}) {
Expand All @@ -80,14 +82,17 @@ func (h Handlers) Download(rw http.ResponseWriter, req *http.Request) {

return
}
} else if ph.Hash == sum {

case ph.Hash == sum:
rw.WriteHeader(http.StatusNotModified)

return

default:
logger.Warn().Str("recorded_hash", ph.Hash).Str("client_hash", sum).Msg("Plugin archive hash mismatch")
}

span.AddEvent("module.download", trace.WithAttributes(attributes...))
logger.Error().Msgf("Someone is trying to hack the archive: %v", sum)
}

span.SetAttributes(attributes...)
Expand Down Expand Up @@ -579,6 +584,8 @@ func (h Handlers) Validate(rw http.ResponseWriter, req *http.Request) {
return
}

logger.Warn().Str("recorded_hash", ph.Hash).Str("client_hash", headerSum).Msg("Plugin archive hash mismatch")

rw.WriteHeader(http.StatusNotFound)
}

Expand Down
Loading