Skip to content

Commit 39d6065

Browse files
committed
Fixes from self-review
Signed-off-by: Spike Curtis <spike@coder.com>
1 parent 2be6cf0 commit 39d6065

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

provisioner/echo/serve.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ func (e *echo) Apply(sess *provisionersdk.Session, req *proto.ApplyRequest, canc
188188

189189
// some tests use Echo without a complete response to test cancel
190190
<-canceledOrComplete
191-
// we have to return a clean Complete or the status will go to "failed"
192191
return provisionersdk.ApplyErrorf("canceled")
193192
}
194193

provisionersdk/session.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ func (s *Session) Context() context.Context {
177177
func (s *Session) ExtractArchive() error {
178178
ctx := s.Context()
179179

180-
//s.ProvisionLog(proto.LogLevel_INFO, "Setting up")
181-
182180
s.Logger.Info(ctx, "unpacking template source archive",
183181
slog.F("size_bytes", len(s.Config.TemplateSourceArchive)),
184182
)
@@ -194,7 +192,11 @@ func (s *Session) ExtractArchive() error {
194192
}
195193
return xerrors.Errorf("read template source archive: %w", err)
196194
}
197-
// #nosec
195+
// Security: don't untar absolute or relative paths, as this can allow a malicious tar to overwrite
196+
// files outside the workdir.
197+
if !filepath.IsLocal(header.Name) {
198+
return xerrors.Errorf("refusing to extract to non-local path")
199+
}
198200
headerPath := filepath.Join(s.WorkDirectory, header.Name)
199201
if !strings.HasPrefix(headerPath, filepath.Clean(s.WorkDirectory)) {
200202
return xerrors.New("tar attempts to target relative upper directory")

0 commit comments

Comments
 (0)