Skip to content

Commit 4cde6db

Browse files
committed
encode blockid via base64 url encoding to avoid security problems
1 parent 1c641fe commit 4cde6db

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

routers/api/actions/artifacts_chunks.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,15 @@ func listChunksByRunIDV4(st storage.ObjectStorage, runID, artifactID int64, blis
140140
// no matter the subdirectory setting in storage config
141141
item := chunkFileItem{Path: storageDir + "/" + baseName, ArtifactID: artifactID}
142142
var size int64
143-
var chunkName string
144-
if _, err := fmt.Sscanf(baseName, "block-%d-%d-%s", &item.RunID, &size, &chunkName); err != nil {
143+
var b64chunkName string
144+
if _, err := fmt.Sscanf(baseName, "block-%d-%d-%s", &item.RunID, &size, &b64chunkName); err != nil {
145145
return fmt.Errorf("parse content range error: %v", err)
146146
}
147+
rchunkName, err := base64.URLEncoding.DecodeString(b64chunkName)
148+
if err != nil {
149+
return fmt.Errorf("failed to parse chunkName: %v", err)
150+
}
151+
chunkName := string(rchunkName)
147152
item.End = item.Start + size - 1
148153
if _, ok := chunkMap[chunkName]; ok {
149154
chunkMap[chunkName] = &item

routers/api/actions/artifactsv4.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ func (r *artifactV4Routes) uploadArtifact(ctx *ArtifactContext) {
327327
return
328328
}
329329
} else {
330-
_, err := r.fs.Save(fmt.Sprintf("tmp%d/block-%d-%d-%s", task.Job.RunID, task.Job.RunID, ctx.Req.ContentLength, blockid), ctx.Req.Body, -1)
330+
_, err := r.fs.Save(fmt.Sprintf("tmp%d/block-%d-%d-%s", task.Job.RunID, task.Job.RunID, ctx.Req.ContentLength, base64.URLEncoding.EncodeToString([]byte(blockid))), ctx.Req.Body, -1)
331331
if err != nil {
332332
log.Error("Error runner api getting task: task is not running")
333333
ctx.Error(http.StatusInternalServerError, "Error runner api getting task: task is not running")

0 commit comments

Comments
 (0)