Skip to content

Commit

Permalink
[preprocessor/webhook] verify wacz file hash vs browsertrix webhook e…
Browse files Browse the repository at this point in the history
…vent
  • Loading branch information
williamchong committed Jun 18, 2024
1 parent 9d96819 commit cba5e97
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions webhook/browsertrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,18 @@ func handleBrowsertrixEvent(w http.ResponseWriter, r *http.Request) {
return
}

if fileAttributes["sha256"] != e.Resources[0].Hash {
log.Printf("Hash mismatch: %s != %s", fileAttributes["sha256"], e.Resources[0].Hash)
writeJsonResponse(w, http.StatusInternalServerError, map[string]string{"error": "hash mismatch"})
return
}

if fileAttributes["file_size"] != e.Resources[0].Size {
log.Printf("Size mismatch: %d != %d", fileAttributes["file_size"], e.Resources[0].Size)
writeJsonResponse(w, http.StatusInternalServerError, map[string]string{"error": "size mismatch"})
return
}

metadataMap, err := wacz.GetVerifiedMetadata(tempFilePath)
if err != nil {
log.Printf("Failed to get metadata: %s", err.Error())
Expand Down

0 comments on commit cba5e97

Please sign in to comment.