Skip to content
Merged
Changes from all commits
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
10 changes: 9 additions & 1 deletion ssrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,23 @@ func (g *Guardian) Safe(network string, address string, _ syscall.RawConn) error
return fmt.Errorf("%w: could not parse %s: %s", ErrInvalidHostPort, address, err)
}

return g.SafeAddrPort(ipport)
}

// SafeAddrPort operates like Safe except only the port and IP address are checked.
func (g *Guardian) SafeAddrPort(ipport netip.AddrPort) error {
if g.ports != nil {
port := ipport.Port()
if !slices.Contains(g.ports, port) {
return fmt.Errorf("%w: %d is not a permitted port (%s)", ErrProhibitedPort, port, g.strPorts)
}
}

ip := ipport.Addr()
return g.SafeAddr(ipport.Addr())
}

// SafeAddrPort operates like Safe except only the IP address is checked.
func (g *Guardian) SafeAddr(ip netip.Addr) error {
if ip.Is6() {
for _, net := range g.allowedv6Prefixes {
if net.Contains(ip) {
Expand Down
Loading