Skip to content

Commit df60acd

Browse files
committed
addressing resource retention issues
1 parent db8511c commit df60acd

File tree

3 files changed

+13
-94
lines changed

3 files changed

+13
-94
lines changed

internal/net/http/http.go

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import (
1212
"io"
1313
"net"
1414
"net/http"
15-
"net/http/cookiejar"
16-
"net/url"
1715
"regexp"
1816
"runtime"
1917
"strconv"
@@ -83,20 +81,22 @@ type BasicAuth struct {
8381
}
8482

8583
func init() {
86-
jar, _ := cookiejar.New(nil)
8784
DefaultClient = &http.Client{
8885
Timeout: httpTimeout,
8986
Transport: &http.Transport{
9087
Proxy: http.ProxyFromEnvironment,
9188
DialContext: amassnet.DialContext,
92-
MaxIdleConns: 200,
93-
MaxConnsPerHost: 50,
89+
ForceAttemptHTTP2: false,
90+
MaxIdleConns: 128,
91+
MaxConnsPerHost: 8,
92+
MaxIdleConnsPerHost: 1,
9493
IdleConnTimeout: 10 * time.Second,
9594
TLSHandshakeTimeout: handshakeTimeout,
96-
ExpectContinueTimeout: 5 * time.Second,
95+
ResponseHeaderTimeout: 5 * time.Second,
96+
ExpectContinueTimeout: 1 * time.Second,
9797
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
9898
},
99-
Jar: jar,
99+
Jar: nil,
100100
}
101101

102102
switch runtime.GOOS {
@@ -170,28 +170,6 @@ func RespToAmassResponse(resp *http.Response) *Response {
170170
}
171171
}
172172

173-
// CopyCookies copies cookies from one domain to another. Some of our data
174-
// sources rely on shared auth tokens and this avoids sending extra requests
175-
// to have the site reissue cookies for the other domains.
176-
func CopyCookies(src string, dest string) {
177-
srcURL, _ := url.Parse(src)
178-
destURL, _ := url.Parse(dest)
179-
DefaultClient.Jar.SetCookies(destURL, DefaultClient.Jar.Cookies(srcURL))
180-
}
181-
182-
// CheckCookie checks if a cookie exists in the cookie jar for a given host
183-
func CheckCookie(urlString string, cookieName string) bool {
184-
cookieURL, _ := url.Parse(urlString)
185-
found := false
186-
for _, cookie := range DefaultClient.Jar.Cookies(cookieURL) {
187-
if cookie.Name == cookieName {
188-
found = true
189-
break
190-
}
191-
}
192-
return found
193-
}
194-
195173
// RequestWebPage returns the response headers, body, and status code for the provided URL when successful.
196174
func RequestWebPage(ctx context.Context, r *Request) (*Response, error) {
197175
if r == nil {

internal/net/http/http_test.go

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -19,70 +19,6 @@ import (
1919
amassdns "github.com/owasp-amass/amass/v5/internal/net/dns"
2020
)
2121

22-
func TestCopyCookies(t *testing.T) {
23-
u, _ := url.Parse("http://owasp.org")
24-
DefaultClient.Jar.SetCookies(u, []*http.Cookie{{
25-
Name: "Test",
26-
Value: "Cookie",
27-
}})
28-
CopyCookies("http://owasp.org", "http://example.com")
29-
30-
u2, _ := url.Parse("http://example.com")
31-
if c := DefaultClient.Jar.Cookies(u2); len(c) == 0 || c[0].Value != "Cookie" {
32-
t.Error("Failed to copy the cookie")
33-
}
34-
}
35-
36-
func TestCheckCookie(t *testing.T) {
37-
type args struct {
38-
urlString string
39-
cookieName string
40-
}
41-
tests := []struct {
42-
name string
43-
init func()
44-
args args
45-
want bool
46-
}{
47-
{
48-
name: "basic-success",
49-
init: func() {
50-
sampleURL, err := url.Parse("http://owasp.org")
51-
if err != nil {
52-
t.Errorf("CheckCookie() parse error: got error = %v", err)
53-
}
54-
55-
cookies := []*http.Cookie{{Name: "cookie1", Value: "sample cookie value"}}
56-
DefaultClient.Jar.SetCookies(sampleURL, cookies)
57-
58-
},
59-
args: args{
60-
urlString: "https://owasp.org",
61-
cookieName: "cookie1",
62-
},
63-
want: true,
64-
},
65-
{
66-
name: "basic-failure",
67-
init: func() {},
68-
args: args{
69-
urlString: "http://domain.local",
70-
cookieName: "cookie2",
71-
},
72-
want: false,
73-
},
74-
}
75-
76-
for _, tt := range tests {
77-
t.Run(tt.name, func(t *testing.T) {
78-
tt.init()
79-
if got := CheckCookie(tt.args.urlString, tt.args.cookieName); got != tt.want {
80-
t.Errorf("CheckCookie() = %v, want %v", got, tt.want)
81-
}
82-
})
83-
}
84-
}
85-
8622
func TestRequestWebPage(t *testing.T) {
8723
name := "caffix"
8824
pass := "OWASP"

internal/net/network.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net"
1212
"strconv"
1313
"strings"
14+
"time"
1415
)
1516

1617
// IPv4RE is a regular expression that will match an IPv4 address.
@@ -57,7 +58,11 @@ func init() {
5758

5859
// DialContext performs the dial using global variables (e.g. LocalAddr).
5960
func DialContext(ctx context.Context, network, addr string) (net.Conn, error) {
60-
d := &net.Dialer{DualStack: true}
61+
d := &net.Dialer{
62+
DualStack: true,
63+
Timeout: 10 * time.Second,
64+
KeepAlive: 30 * time.Second,
65+
}
6166

6267
_, p, err := net.SplitHostPort(addr)
6368
if err != nil {

0 commit comments

Comments
 (0)