Skip to content

Commit 28ab17d

Browse files
committed
haproxy Cookie id leaks information about software
Resolves: bz1328030 This obfuscates the cookie name my hashing the original name. Signed-off-by: Phil Cameron <[email protected]>
1 parent c024891 commit 28ab17d

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

images/router/haproxy/conf/haproxy-config.template

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ backend be_edge_http_{{$cfgIdx}}
217217
http-request set-header X-Forwarded-Proto http if !{ ssl_fc }
218218
http-request set-header X-Forwarded-Proto https if { ssl_fc }
219219
{{ if (eq $cfg.TLSTermination "") }}
220-
cookie OPENSHIFT_{{$cfgIdx}}_SERVERID insert indirect nocache httponly
220+
cookie {{$cfg.RoutingKeyName}} insert indirect nocache httponly
221221
{{ else }}
222-
cookie OPENSHIFT_EDGE_{{$cfgIdx}}_SERVERID insert indirect nocache httponly secure
222+
cookie {{$cfg.RoutingKeyName}} insert indirect nocache httponly secure
223223
{{ end }}
224224
http-request set-header Forwarded for=%[src];host=%[req.hdr(host)];proto=%[req.hdr(X-Forwarded-Proto)]
225225
{{ range $idx, $endpoint := endpointsForAlias $cfg $serviceUnit }}
@@ -243,7 +243,7 @@ backend be_secure_{{$cfgIdx}}
243243
option redispatch
244244
balance leastconn
245245
timeout check 5000ms
246-
cookie OPENSHIFT_REENCRYPT_{{$cfgIdx}}_SERVERID insert indirect nocache httponly secure
246+
cookie {{$cfg.RoutingKeyName}} insert indirect nocache httponly secure
247247
{{ range $idx, $endpoint := endpointsForAlias $cfg $serviceUnit }}
248248
server {{$endpoint.IdHash}} {{$endpoint.IP}}:{{$endpoint.Port}} ssl check inter 5000ms verify required ca-file {{ $workingDir }}/cacerts/{{$cfgIdx}}.pem cookie {{$endpoint.IdHash}}
249249
{{ end }}

pkg/router/template/router.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package templaterouter
22

33
import (
4+
"crypto/md5"
45
"encoding/json"
56
"fmt"
67
"io/ioutil"
@@ -450,6 +451,9 @@ func (r *templateRouter) AddRoute(id string, route *routeapi.Route, host string)
450451
}
451452
}
452453

454+
key := fmt.Sprintf("%s %s", config.TLSTermination, backendKey)
455+
config.RoutingKeyName = fmt.Sprintf("%x", md5.Sum([]byte(key)))
456+
453457
//create or replace
454458
frontend.ServiceAliasConfigs[backendKey] = config
455459
r.state[id] = frontend

pkg/router/template/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ type ServiceAliasConfig struct {
3737
// insecure connections to an edge-terminated route:
3838
// none (or disable), allow or redirect
3939
InsecureEdgeTerminationPolicy routeapi.InsecureEdgeTerminationPolicyType
40+
// Hash of the route name - used to obscure cookieId
41+
RoutingKeyName string
4042
}
4143

4244
type ServiceAliasConfigStatus string

test/integration/router_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,12 @@ func getRoute(routerUrl string, hostName string, protocol string, headers map[st
10351035
return "", fmt.Errorf("GET of %s returned: %d", url, resp.StatusCode)
10361036
}
10371037
respBody, err := ioutil.ReadAll(resp.Body)
1038+
cookies := resp.Cookies()
1039+
for _, cookie := range cookies {
1040+
if len(cookie.Name) != 32 || len(cookie.Value) != 32 {
1041+
return "", fmt.Errorf("GET of %s returned bad cookie %s=%s", url, cookie.Name, cookie.Value)
1042+
}
1043+
}
10381044
return string(respBody), err
10391045

10401046
case "ws", "wss":

0 commit comments

Comments
 (0)