Skip to content

SONARSEC-6429: Create rule S5144 Server-side requests should not be vulnerable to forging attacks for Go #5053

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

Merged
merged 18 commits into from
May 23, 2025

Conversation

github-actions[bot]
Copy link
Contributor

You can preview this rule here (updated a few minutes after each push).

Review

A dedicated reviewer checked the rule description successfully for:

  • logical errors and incorrect information
  • information gaps and missing content
  • text style and tone
  • PR summary and labels follow the guidelines

@daniel-teuchert-sonarsource daniel-teuchert-sonarsource marked this pull request as ready for review May 16, 2025 10:10
@daniel-teuchert-sonarsource daniel-teuchert-sonarsource changed the title Create rule S5144 SONARSEC-6429: Create rule S5144 Server-side requests should not be vulnerable to forging attacks for Go May 19, 2025
github-actions bot and others added 3 commits May 19, 2025 10:20
…ction attacks for Go (#5039)

* Add go to rule S2091

* Add initial docs

* Use regexp for compliant examples

* Tidy up

---------

Co-authored-by: teemu-rytilahti-sonarsource <teemu-rytilahti-sonarsource@users.noreply.github.com>
Co-authored-by: Teemu Rytilahti <teemu.rytilahti@sonarsource.com>
* Add go to rule S5145

* Add description and example for Go standard library

* Add example for Fiber

---------

Co-authored-by: daniel-teuchert-sonarsource <daniel-teuchert-sonarsource@users.noreply.github.com>
Co-authored-by: Daniel Teuchert <daniel.teuchert@sonarsource.com>
Co-authored-by: daniel-teuchert-sonarsource <141642369+daniel-teuchert-sonarsource@users.noreply.github.com>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a couple of nitpicks, but this looks good to me 👍

Comment on lines 12 to 14
URL `\https://example.commit.malicious.io`.
URL `https://example.commit.malicious.io`.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid using nothing else but the IANA-reserved example domains for examples, especially if this domain is not under our control.

Comment on lines 54 to 55
"https://example.com": true,
"https://example.com/": true,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it intentional to use the same domain with and without a trailing slash?

I guess that this pattern gets used for reverse proxying in production, so maybe worth considering to show an example with prefix-matching even when it's a bit more complex?

func Example(c *fiber.Ctx) error {
url := c.Query("url")
agent := fiber.Get(url)
statusCode, body, errs := agent.Bytes()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
statusCode, body, errs := agent.Bytes()
statusCode, body, errs := agent.String()

This would avoid the need to do a string cast below.


func Example(w http.ResponseWriter, req *http.Request) {
url := req.FormValue("url")
resp, err := http.Get(url) // Noncompliant

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
resp, err := http.Get(url) // Noncompliant
resp, err := http.Get(url)


statusCode, body, err := fasthttp.Get(nil, url)
if err != nil {
fmt.Fprintf(ctx, "Error when making request: %s\n", err.Error())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff view is showing that this line has been changed between the compliant and non compliant versions, which looks off. Any ideas if we can influence that anyhow?

"https://example.com/": true,
}
if _, ok := allowedURLs[url]; !ok {
fmt.Fprint(ctx, "Specified host is not allowed")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fmt.Fprint(ctx, "Specified host is not allowed")
fmt.Fprint(ctx, "Specified url is not allowed")

Would be consistent with the allowedUrls naming. Applies also to other examples, so I'm not repeating myself below.

Copy link

Quality Gate passed Quality Gate passed for 'rspec-tools'

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
0 Dependency risks
No data about Coverage
No data about Duplication

See analysis details on SonarQube

Copy link

Quality Gate passed Quality Gate passed for 'rspec-frontend'

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
0 Dependency risks
No data about Coverage
No data about Duplication

See analysis details on SonarQube

@daniel-teuchert-sonarsource daniel-teuchert-sonarsource added this pull request to the merge queue May 23, 2025
Merged via the queue into master with commit d620b77 May 23, 2025
11 of 12 checks passed
@daniel-teuchert-sonarsource daniel-teuchert-sonarsource deleted the rule/S5144-add-go branch May 23, 2025 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants