Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(bugbash) fixes potential file inclusion via variable. #490

Merged
merged 3 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion cmd/tink-cli/cmd/hardware/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -84,7 +85,7 @@ func readDataFromStdin() string {
}

func readDataFromFile() string {
f, err := os.Open(file)
f, err := os.Open(filepath.Clean(file))
if err != nil {
log.Fatal(err)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/tink-cli/cmd/template/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"log"
"os"
"path/filepath"

"github.com/spf13/cobra"
"github.com/tinkerbell/tink/client"
Expand Down Expand Up @@ -39,7 +40,7 @@ $ tink template create --file /tmp/example.tmpl
if isInputFromPipe() {
reader = os.Stdin
} else {
f, err := os.Open(filePath)
f, err := os.Open(filepath.Clean(filePath))
if err != nil {
log.Fatal(err)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/tink-worker/internal/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -473,7 +474,7 @@ func sendUpdate(ctx context.Context, logger log.Logger, client pb.WorkflowServic
}

func openDataFile(wfDir string, l log.Logger) *os.File {
f, err := os.OpenFile(wfDir+string(os.PathSeparator)+dataFile, os.O_RDWR|os.O_CREATE, 0644)
f, err := os.OpenFile(filepath.Clean(wfDir+string(os.PathSeparator)+dataFile), os.O_RDWR|os.O_CREATE, 0600)
if err != nil {
l.Error(err)
os.Exit(1)
Expand Down
5 changes: 3 additions & 2 deletions grpc-server/grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"net"
"os"
"path/filepath"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -110,7 +111,7 @@ func getCerts(facility string, logger log.Logger) (tls.Certificate, []byte, time
certsDir += "/"
}

certFile, err := os.Open(certsDir + "bundle.pem")
certFile, err := os.Open(filepath.Clean(certsDir + "bundle.pem"))
if err != nil {
err = errors.Wrap(err, "failed to open TLS cert")
logger.Error(err)
Expand All @@ -131,7 +132,7 @@ func getCerts(facility string, logger log.Logger) (tls.Certificate, []byte, time
logger.Error(err)
panic(err)
}
keyPEM, err := ioutil.ReadFile(certsDir + "server-key.pem")
keyPEM, err := ioutil.ReadFile(filepath.Clean(certsDir + "server-key.pem"))
if err != nil {
err = errors.Wrap(err, "failed to read TLS key")
logger.Error(err)
Expand Down
3 changes: 2 additions & 1 deletion test/framework/hardware.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"

"github.com/tinkerbell/tink/client"
"github.com/tinkerbell/tink/protos/hardware"
)

func readHwData(file string) ([]byte, error) {
f, err := os.Open(file)
f, err := os.Open(filepath.Clean(file))
if err != nil {
return []byte(""), err
}
Expand Down
3 changes: 2 additions & 1 deletion test/framework/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"context"
"io/ioutil"
"os"
"path/filepath"

"github.com/tinkerbell/tink/client"
"github.com/tinkerbell/tink/protos/template"
)

func readTemplateData(file string) (string, error) {
f, err := os.Open(file)
f, err := os.Open(filepath.Clean(file))
if err != nil {
return "", err
}
Expand Down
3 changes: 2 additions & 1 deletion workflow/template_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"path/filepath"
"text/template"

"github.com/docker/distribution/reference"
Expand Down Expand Up @@ -52,7 +53,7 @@ func MustParse(yamlContent []byte) *Workflow {
// MustParseFromFile parse a template from a file and it panics if any error is
// detected. Ideal to be used in testing.
func MustParseFromFile(path string) *Workflow {
content, err := ioutil.ReadFile(path)
content, err := ioutil.ReadFile(filepath.Clean(path))
if err != nil {
panic(err)
}
Expand Down