Skip to content

Commit 1301ff8

Browse files
committed
fix(security): close open-redirect bypass and integer truncation from CodeQL
sanitizeReturnTo now rejects backslash in second position (browsers treat /\host as scheme-relative). mapUint16 replaces unsafe uint32->uint16 cast for prefix idle-timeout, rejecting out-of-range values at parse time.
1 parent 56b853d commit 1301ff8

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎internal/component/bgp/reactor/config.go‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,8 @@ func parsePrefixLimitFromFamily(familyKey string, entryMap map[string]any, ps *P
609609
ps.PrefixTeardown = v != valFalse
610610
}
611611

612-
if v, ok := mapUint32(prefixMap, "idle-timeout"); ok {
613-
ps.PrefixIdleTimeout = uint16(v) //nolint:gosec // Bounded by YANG uint16 range
612+
if v, ok := mapUint16(prefixMap, "idle-timeout"); ok {
613+
ps.PrefixIdleTimeout = v
614614
}
615615

616616
if v, ok := mapString(prefixMap, "updated"); ok {
@@ -826,6 +826,19 @@ func mapUint8(m map[string]any, key string) (uint8, bool) {
826826
return uint8(n), true
827827
}
828828

829+
// mapUint16 extracts a uint16 value from a map (stored as string).
830+
func mapUint16(m map[string]any, key string) (uint16, bool) {
831+
s, ok := mapString(m, key)
832+
if !ok {
833+
return 0, false
834+
}
835+
n, err := strconv.ParseUint(s, 10, 16)
836+
if err != nil {
837+
return 0, false
838+
}
839+
return uint16(n), true
840+
}
841+
829842
// mapMap extracts a nested map from a map.
830843
func mapMap(m map[string]any, key string) (map[string]any, bool) {
831844
v, ok := m[key]

‎internal/component/web/auth.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ func LoginHandler(store *SessionStore, authenticator authz.Authenticator, loginR
272272
// Only same-origin paths starting with "/" are accepted; everything else
273273
// falls back to "/".
274274
func sanitizeReturnTo(raw string) string {
275-
if raw == "" || raw[0] != '/' || strings.HasPrefix(raw, "//") {
275+
if raw == "" || raw[0] != '/' || strings.HasPrefix(raw, "//") || (len(raw) > 1 && raw[1] == '\\') {
276276
return "/"
277277
}
278278
return raw

0 commit comments

Comments
 (0)