-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Removing singletons #6210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Removing singletons #6210
Conversation
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@@ -55,7 +55,7 @@ | |||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | |||
w.Header().Set("Content-Type", "text/html") | |||
value := r.URL.Query().Get("id") | |||
fmt.Fprintf(w, "This is test matcher text: %v", value) | |||
_, _ = fmt.Fprintf(w, "This is test matcher text: %v", value) |
Check warning
Code scanning / CodeQL
Reflected cross-site scripting Medium
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 22 days ago
To fix the reflected XSS vulnerability, the user-provided input (value
) must be sanitized or escaped before being included in the HTTP response. In Go, the html.EscapeString
function from the html
package is a standard and effective way to escape special characters in a string for safe inclusion in HTML content. This ensures that any potentially malicious input is rendered harmless.
The fix involves:
- Importing the
html
package if not already imported. - Escaping the
value
variable usinghtml.EscapeString
before passing it tofmt.Fprintf
.
The changes will be made in the cmd/integration-test/fuzz.go
file, specifically in the HTTP handler function on line 58.
-
Copy modified line R5 -
Copy modified lines R59-R60
@@ -4,2 +4,3 @@ | ||
"fmt" | ||
"html" | ||
"net/http" | ||
@@ -57,3 +58,4 @@ | ||
value := r.URL.Query().Get("id") | ||
_, _ = fmt.Fprintf(w, "This is test matcher text: %v", value) | ||
escapedValue := html.EscapeString(value) | ||
_, _ = fmt.Fprintf(w, "This is test matcher text: %v", escapedValue) | ||
}) |
@@ -75,7 +75,7 @@ | |||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | |||
w.Header().Set("Content-Type", "text/html") | |||
value := r.URL.Query().Get("id") | |||
fmt.Fprintf(w, "This is test matcher text: %v", value) | |||
_, _ = fmt.Fprintf(w, "This is test matcher text: %v", value) |
Check warning
Code scanning / CodeQL
Reflected cross-site scripting Medium
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 22 days ago
To fix the reflected XSS vulnerability, the user-provided input (value
) should be sanitized or escaped before being included in the HTTP response. In Go, the html.EscapeString
function from the html
package is commonly used to escape special characters in a string, making it safe for inclusion in HTML content. This ensures that any potentially malicious input is rendered as plain text rather than being executed as code.
The changes will be applied to both instances where fmt.Fprintf
is used to write the value
variable to the response (lines 58 and 78). The html
package will also need to be imported.
-
Copy modified line R5 -
Copy modified line R59 -
Copy modified line R79
@@ -4,2 +4,3 @@ | ||
"fmt" | ||
"html" | ||
"net/http" | ||
@@ -57,3 +58,3 @@ | ||
value := r.URL.Query().Get("id") | ||
_, _ = fmt.Fprintf(w, "This is test matcher text: %v", value) | ||
_, _ = fmt.Fprintf(w, "This is test matcher text: %v", html.EscapeString(value)) | ||
}) | ||
@@ -77,3 +78,3 @@ | ||
value := r.URL.Query().Get("id") | ||
_, _ = fmt.Fprintf(w, "This is test matcher text: %v", value) | ||
_, _ = fmt.Fprintf(w, "This is test matcher text: %v", html.EscapeString(value)) | ||
}) |
@@ -120,7 +120,7 @@ | |||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | |||
w.Header().Set("Content-Type", "text/html") | |||
value := r.URL.Query().Get("id") | |||
fmt.Fprintf(w, "This is test matcher text: %v", value) | |||
_, _ = fmt.Fprintf(w, "This is test matcher text: %v", value) |
Check warning
Code scanning / CodeQL
Reflected cross-site scripting Medium
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 22 days ago
To fix the reflected XSS vulnerability, the user-provided input (value
) must be sanitized or escaped before being included in the HTTP response. In Go, the html.EscapeString
function from the html
package is a standard and effective way to escape special HTML characters, such as <
, >
, and &
, which could otherwise be used to inject malicious scripts.
The fix involves:
- Importing the
html
package if it is not already imported. - Escaping the
value
variable usinghtml.EscapeString
before passing it tofmt.Fprintf
.
This ensures that any potentially malicious input is safely encoded and cannot be executed as part of the HTML response.
-
Copy modified line R13 -
Copy modified lines R124-R125
@@ -12,2 +12,3 @@ | ||
"github.com/projectdiscovery/nuclei/v3/pkg/utils/json" | ||
"html" | ||
) | ||
@@ -122,3 +123,4 @@ | ||
value := r.URL.Query().Get("id") | ||
_, _ = fmt.Fprintf(w, "This is test matcher text: %v", value) | ||
escapedValue := html.EscapeString(value) | ||
_, _ = fmt.Fprintf(w, "This is test matcher text: %v", escapedValue) | ||
}) |
@@ -164,7 +164,7 @@ | |||
router := httprouter.New() | |||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | |||
resp := fmt.Sprintf("<html><body>%s</body></html>", r.URL.Query().Get("url")) | |||
fmt.Fprint(w, resp) | |||
_, _ = fmt.Fprint(w, resp) |
Check warning
Code scanning / CodeQL
Reflected cross-site scripting Medium
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 22 days ago
To fix the reflected XSS vulnerability, the user-provided input (r.URL.Query().Get("url")
) must be sanitized or escaped before being included in the HTML response. The html.EscapeString
function from the Go standard library is well-suited for this purpose, as it escapes special characters like <
, >
, and &
to their corresponding HTML entities, preventing the execution of malicious scripts.
The fix involves wrapping the user input with html.EscapeString
before embedding it into the resp
string. This ensures that any potentially harmful characters in the input are safely escaped.
-
Copy modified line R13 -
Copy modified lines R167-R168
@@ -12,2 +12,3 @@ | ||
"github.com/projectdiscovery/nuclei/v3/pkg/utils/json" | ||
"html" | ||
) | ||
@@ -165,3 +166,4 @@ | ||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||
resp := fmt.Sprintf("<html><body>%s</body></html>", r.URL.Query().Get("url")) | ||
escapedURL := html.EscapeString(r.URL.Query().Get("url")) | ||
resp := fmt.Sprintf("<html><body>%s</body></html>", escapedURL) | ||
_, _ = fmt.Fprint(w, resp) |
@@ -1192,7 +1201,7 @@ | |||
func (h *httpVariables) Execute(filePath string) error { | |||
router := httprouter.New() | |||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | |||
fmt.Fprintf(w, "%s\n%s\n%s", r.Header.Get("Test"), r.Header.Get("Another"), r.Header.Get("Email")) | |||
_, _ = fmt.Fprintf(w, "%s\n%s\n%s", r.Header.Get("Test"), r.Header.Get("Another"), r.Header.Get("Email")) |
Check warning
Code scanning / CodeQL
Reflected cross-site scripting Medium
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 21 days ago
To fix the issue, we need to sanitize the user-controlled input retrieved from the HTTP headers before writing it to the HTTP response. The html.EscapeString
function from the html
package in Go is a suitable choice for escaping special characters in the input, making it safe for inclusion in HTML responses.
The fix involves:
- Importing the
html
package if it is not already imported. - Escaping the values retrieved from
r.Header.Get
usinghtml.EscapeString
before passing them tofmt.Fprintf
.
-
Copy modified line R5 -
Copy modified line R1205
@@ -4,2 +4,3 @@ | ||
"errors" | ||
"html" | ||
"fmt" | ||
@@ -1203,3 +1204,3 @@ | ||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||
_, _ = fmt.Fprintf(w, "%s\n%s\n%s", r.Header.Get("Test"), r.Header.Get("Another"), r.Header.Get("Email")) | ||
_, _ = fmt.Fprintf(w, "%s\n%s\n%s", html.EscapeString(r.Header.Get("Test")), html.EscapeString(r.Header.Get("Another")), html.EscapeString(r.Header.Get("Email"))) | ||
}) |
@@ -1192,7 +1201,7 @@ | |||
func (h *httpVariables) Execute(filePath string) error { | |||
router := httprouter.New() | |||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | |||
fmt.Fprintf(w, "%s\n%s\n%s", r.Header.Get("Test"), r.Header.Get("Another"), r.Header.Get("Email")) | |||
_, _ = fmt.Fprintf(w, "%s\n%s\n%s", r.Header.Get("Test"), r.Header.Get("Another"), r.Header.Get("Email")) |
Check warning
Code scanning / CodeQL
Reflected cross-site scripting Medium
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 22 days ago
To fix the reflected cross-site scripting vulnerability, the user-controlled input (r.Header.Get(...)
) should be sanitized or escaped before being written to the HTTP response. In Go, the html.EscapeString
function from the html
package can be used to escape special characters in the input, making it safe for inclusion in HTML content.
The fix involves:
- Importing the
html
package if not already imported. - Escaping the values retrieved from
r.Header.Get(...)
usinghtml.EscapeString
before passing them tofmt.Fprintf
.
The changes will be applied to the cmd/integration-test/http.go
file, specifically to the router.GET
handler in the httpVariables.Execute
method.
-
Copy modified line R5 -
Copy modified line R1205
@@ -4,2 +4,3 @@ | ||
"errors" | ||
"html" | ||
"fmt" | ||
@@ -1203,3 +1204,3 @@ | ||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||
_, _ = fmt.Fprintf(w, "%s\n%s\n%s", r.Header.Get("Test"), r.Header.Get("Another"), r.Header.Get("Email")) | ||
_, _ = fmt.Fprintf(w, "%s\n%s\n%s", html.EscapeString(r.Header.Get("Test")), html.EscapeString(r.Header.Get("Another")), html.EscapeString(r.Header.Get("Email"))) | ||
}) |
@@ -1449,7 +1458,7 @@ | |||
func (h *ConstantWithCliVar) Execute(filePath string) error { | |||
router := httprouter.New() | |||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | |||
fmt.Fprint(w, r.URL.Query().Get("p")) | |||
_, _ = fmt.Fprint(w, r.URL.Query().Get("p")) |
Check warning
Code scanning / CodeQL
Reflected cross-site scripting Medium
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 22 days ago
To fix the issue, the user-provided value from the query parameter p
should be sanitized or escaped before being written to the HTTP response. In Go, the html.EscapeString
function from the html
package can be used to escape special characters in the user input, making it safe to include in the response.
The fix involves:
- Importing the
html
package if it is not already imported. - Escaping the value of
r.URL.Query().Get("p")
usinghtml.EscapeString
before passing it tofmt.Fprint
.
This ensures that any potentially malicious input is neutralized, preventing XSS attacks.
-
Copy modified line R14 -
Copy modified lines R1462-R1463
@@ -13,2 +13,3 @@ | ||
"strings" | ||
"html" | ||
"time" | ||
@@ -1460,3 +1461,4 @@ | ||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||
_, _ = fmt.Fprint(w, r.URL.Query().Get("p")) | ||
escapedParam := html.EscapeString(r.URL.Query().Get("p")) | ||
_, _ = fmt.Fprint(w, escapedParam) | ||
}) |
@@ -1486,10 +1495,10 @@ | |||
func (h *httpDisablePathAutomerge) Execute(filePath string) error { | |||
router := httprouter.New() | |||
router.GET("/api/v1/test", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | |||
fmt.Fprint(w, r.URL.Query().Get("id")) | |||
_, _ = fmt.Fprint(w, r.URL.Query().Get("id")) |
Check warning
Code scanning / CodeQL
Reflected cross-site scripting Medium
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 21 days ago
To fix the reflected cross-site scripting vulnerability, the user-provided input (id
parameter) must be sanitized or escaped before being written to the HTTP response. In Go, the html.EscapeString
function from the html
package is commonly used to escape special characters in a string, making it safe for inclusion in HTML content.
Steps to fix:
- Import the
html
package if it is not already imported. - Use
html.EscapeString
to escape the value ofr.URL.Query().Get("id")
before passing it tofmt.Fprint
.
This ensures that any special characters in the user input (e.g., <
, >
, &
) are converted to their HTML-escaped equivalents (e.g., <
, >
, &
), preventing the execution of malicious scripts.
-
Copy modified line R6 -
Copy modified line R1499
@@ -5,2 +5,3 @@ | ||
"fmt" | ||
"html" | ||
"net/http" | ||
@@ -1497,3 +1498,3 @@ | ||
router.GET("/api/v1/test", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||
_, _ = fmt.Fprint(w, r.URL.Query().Get("id")) | ||
_, _ = fmt.Fprint(w, html.EscapeString(r.URL.Query().Get("id"))) | ||
}) |
}) | ||
router.GET("/path2", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||
body, _ := io.ReadAll(r.Body) | ||
fmt.Fprintf(w, "%s", body) | ||
_, _ = fmt.Fprintf(w, "%s", body) |
Check warning
Code scanning / CodeQL
Reflected cross-site scripting Medium
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 22 days ago
To fix the issue, the user-provided input (body
) must be sanitized or escaped before being written to the HTTP response. In Go, the html.EscapeString
function can be used to escape special HTML characters, ensuring that any malicious input is rendered harmless in the browser. This change should be applied to the fmt.Fprintf
call on line 169.
Steps to fix:
- Import the
html
package if not already imported. - Use
html.EscapeString
to sanitize thebody
variable before writing it to the response.
-
Copy modified line R10 -
Copy modified line R170
@@ -9,2 +9,3 @@ | ||
"strings" | ||
"html" | ||
|
||
@@ -168,3 +169,3 @@ | ||
body, _ := io.ReadAll(r.Body) | ||
_, _ = fmt.Fprintf(w, "%s", body) | ||
_, _ = fmt.Fprintf(w, "%s", html.EscapeString(string(body))) | ||
}) |
}) | ||
// path2 responds with the value of the "extracted" query parameter, e.g.: /path2?extracted=blog.projectdiscovery.io => blog.projectdiscovery.io | ||
router.GET("/path2", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||
fmt.Fprintf(w, "%s", r.URL.Query().Get("extracted")) | ||
_, _ = fmt.Fprintf(w, "%s", r.URL.Query().Get("extracted")) |
Check warning
Code scanning / CodeQL
Reflected cross-site scripting Medium
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 22 days ago
To fix the reflected XSS vulnerability, the user-controlled input (r.URL.Query().Get("extracted")
) must be sanitized or encoded before being written to the HTTP response. The best approach is to use the html.EscapeString
function from the Go standard library, which escapes special HTML characters (<
, >
, &
, etc.) to their corresponding HTML entities. This ensures that any malicious input is rendered harmless in the browser.
Steps to fix:
- Import the
html
package from the Go standard library. - Replace the direct usage of
r.URL.Query().Get("extracted")
withhtml.EscapeString(r.URL.Query().Get("extracted"))
in thefmt.Fprintf
call on line 221.
-
Copy modified line R5 -
Copy modified line R222
@@ -4,2 +4,3 @@ | ||
"fmt" | ||
"html" | ||
"io" | ||
@@ -220,3 +221,3 @@ | ||
router.GET("/path2", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||
_, _ = fmt.Fprintf(w, "%s", r.URL.Query().Get("extracted")) | ||
_, _ = fmt.Fprintf(w, "%s", html.EscapeString(r.URL.Query().Get("extracted"))) | ||
}) |
Proposed changes
Closes #5239
Checklist