Skip to content
This repository was archived by the owner on Feb 27, 2026. It is now read-only.

Commit 49fe2e4

Browse files
authored
Add doc for rule G107 (#13)
I added introduction + bad examples + good exaples + reference links. Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
1 parent f5699a7 commit 49fe2e4

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
id: g107
3+
title: G107: Url provided to HTTP request as taint input
4+
---
5+
6+
Getting an URL from an untrusted source like user input gives the ability of an attacker to redirect your application to bad websites and perform additional attacks.
7+
One of the examples is as shown below the [http.Get()](https://golang.org/pkg/net/http/#Client.Get) function issues a GET to the specified URL and if the result is appropriate GET will follow the redirect after calling Client's CheckRedirect function. That means that the attacker can send your application to various places.
8+
9+
This problem can be used to achieve [SSRF](https://www.acunetix.com/blog/articles/server-side-request-forgery-vulnerability/) atttacks via http requests with variable url.
10+
11+
## Example problematic code:
12+
13+
```
14+
package main
15+
import (
16+
"net/http"
17+
"io/ioutil"
18+
"fmt"
19+
"os"
20+
)
21+
func main() {
22+
url := os.Getenv("tainted_url")
23+
resp, err := http.Get(url)
24+
if err != nil {
25+
panic(err)
26+
}
27+
defer resp.Body.Close()
28+
body, err := ioutil.ReadAll(resp.Body)
29+
if err != nil {
30+
panic(err)
31+
}
32+
fmt.Printf("%s", body)
33+
}
34+
```
35+
36+
## Gosec command line output
37+
38+
```
39+
[examples/main.go:12] - G107: Potential HTTP request made with variable url (Confidence: MEDIUM, Severity: MEDIUM)
40+
> http.Get(url)
41+
```
42+
43+
## The right way
44+
45+
```
46+
package main
47+
48+
import (
49+
"fmt"
50+
"net/http"
51+
)
52+
53+
const url = "http://127.0.0.1"
54+
55+
func main() {
56+
resp, err := http.Get(url)
57+
if err != nil {
58+
fmt.Println(err)
59+
}
60+
fmt.Println(resp.Status)
61+
}
62+
```
63+
64+
## See also
65+
66+
* http://projects.webappsec.org/w/page/13246981/URL%20Redirector%20Abuse
67+
* https://www.owasp.org/index.php/Top_10_2010-A10-Unvalidated_Redirects_and_Forwards

website/sidebars.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"rules/g101",
66
"rules/g102",
77
"rules/g103",
8-
"rules/g104"
8+
"rules/g104",
9+
"rules/g107"
910
]
1011
}
1112
}

0 commit comments

Comments
 (0)