Skip to content

Commit 141db2d

Browse files
arschlesAaron Schlesinger
authored andcommitted
fix(controller.go): check for shellshock exploits
ported from the old publish-release-controller.go in pkg/src
1 parent f041fbf commit 141db2d

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

pkg/gitreceive/controller.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ import (
55
"encoding/json"
66
"fmt"
77
"net/http"
8+
"regexp"
89
"strings"
910

1011
"github.com/deis/builder/pkg"
1112
)
1213

14+
var (
15+
potentialExploit = regexp.MustCompile(`\(\)\s+\{[^\}]+\};\s+(.*)`)
16+
)
17+
1318
type unexpectedControllerStatusCode struct {
1419
endpoint string
1520
expected int
@@ -77,8 +82,14 @@ func publishRelease(conf *Config, builderKey string, buildHook *pkg.BuildHook) (
7782
if err := json.NewEncoder(&b).Encode(buildHook); err != nil {
7883
return nil, err
7984
}
85+
86+
postBody := strings.Replace(string(b.Bytes()), "'", "", -1)
87+
if potentialExploit.MatchString(postBody) {
88+
return nil, fmt.Errorf("an environment variable in the app is trying to exploit Shellshock")
89+
}
90+
8091
url := controllerURLStr(conf, "v2", "hooks", "build")
81-
req, err := http.NewRequest("POST", url, &b)
92+
req, err := http.NewRequest("POST", url, strings.NewReader(postBody))
8293
if err != nil {
8394
return nil, err
8495
}

0 commit comments

Comments
 (0)