Skip to content
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

[🐞] Found 3 gosec issues: CWE-78 and CWE-242 #5

Closed
koddr opened this issue Feb 2, 2020 · 4 comments
Closed

[🐞] Found 3 gosec issues: CWE-78 and CWE-242 #5

koddr opened this issue Feb 2, 2020 · 4 comments

Comments

@koddr
Copy link
Contributor

koddr commented Feb 2, 2020

Your environment:

  • Fiber Web Framework [e.g. 1.2.3]: 1.2.3
  • OS [e.g. macOS 10.14.6]: macOS 10.14.6
  • Golang [e.g. 1.13.7]: 1.13.7

Describe the bug

A clear and concise description of what the bug is.

To Reproduce

Steps to reproduce the behavior:

  1. Install securego/gosec
  2. Run $ gosec ./...
  3. See security report:

Issue G204 (CWE-78): Subprocess launched with function call as argument or cmd arguments:

[/Users/koddr/CodeProjects/fiber/listen.go:101] - G204 (CWE-78): Subprocess launched with function call as argument or cmd arguments (Confidence: HIGH, Severity: MEDIUM)
  > exec.Command(os.Args[0], "-prefork", "-child")

Issue G103 (CWE-242): Use of unsafe calls should be audited:

[/Users/koddr/CodeProjects/fiber/utils.go:82] - G103 (CWE-242): Use of unsafe calls should be audited (Confidence: HIGH, Severity: LOW)
  > unsafe.Pointer(&b)

[/Users/koddr/CodeProjects/fiber/utils.go:86] - G103 (CWE-242): Use of unsafe calls should be audited (Confidence: HIGH, Severity: LOW)
  > unsafe.Pointer(&s)

Expected behavior

No security issues on report.

Screenshots

No need.

Additional context

Full console output:

$ sw_vers

ProductName:    Mac OS X
ProductVersion: 10.14.6
BuildVersion:   18G2022

$ go version 

go version go1.13.7 darwin/amd64

$ gosec ./...

[gosec] 2020/02/02 12:32:41 Including rules: default
[gosec] 2020/02/02 12:32:41 Excluding rules: default
[gosec] 2020/02/02 12:32:41 Import directory: /Users/koddr/CodeProjects/fiber
[gosec] 2020/02/02 12:32:42 Checking package: fiber
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/application.go
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/context.go
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/listen.go
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/methods.go
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/request.go
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/response.go
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/router.go
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/static.go
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/status.go
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/types.go
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/utils.go
[gosec] 2020/02/02 12:32:42 Import directory: /Users/koddr/CodeProjects/fiber/middleware
[gosec] 2020/02/02 12:32:42 Checking package: middleware
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/middleware/cors.go
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/middleware/helmet.go

Results:

[/Users/koddr/CodeProjects/fiber/listen.go:101] - G204 (CWE-78): Subprocess launched with function call as argument or cmd arguments (Confidence: HIGH, Severity: MEDIUM)
  > exec.Command(os.Args[0], "-prefork", "-child")

[/Users/koddr/CodeProjects/fiber/utils.go:82] - G103 (CWE-242): Use of unsafe calls should be audited (Confidence: HIGH, Severity: LOW)
  > unsafe.Pointer(&b)

[/Users/koddr/CodeProjects/fiber/utils.go:86] - G103 (CWE-242): Use of unsafe calls should be audited (Confidence: HIGH, Severity: LOW)
  > unsafe.Pointer(&s)

Summary:
   Files: 13
   Lines: 1671
   Nosec: 0
  Issues: 3
@Fenny Fenny closed this as completed Feb 2, 2020
@koddr
Copy link
Contributor Author

koddr commented Feb 3, 2020

OK, issue closed, but what's decision do you have? 😉

I mean, it's normal to have this issues now (Fiber is too young), but if we can use external tools (like gosec) for checking security (an not so) issues at code and save our users — let's do it! 😀

This is some info about G103 (CWE-242) issue:

  1. https://securego.io/docs/rules/g103.html
  2. https://go101.org/article/unsafe.html

I fixed two similar issues at #4, but I need help, because I'm not author of Fiber, unfortunately, and don't know why it's important to use unsafe.Pointer()...

@Fenny
Copy link
Member

Fenny commented Feb 3, 2020

@koddr Thanks for your contribution!
I merged your pull request and addressed your gosec report in the source.

unsafe.Pointer() is used to convert a byte slice to a string without memory allocation.

@koddr
Copy link
Contributor Author

koddr commented Feb 3, 2020

@Fenny thx for awesome framework, btw 😃

unsafe.Pointer() is used to convert a byte slice to a string without memory allocation.

Potentially, how we can solve this? Or not any other ways to do this (so easy as unsafe)?
I will go deep to this issue 👌

@Fenny
Copy link
Member

Fenny commented Feb 3, 2020

@koddr , Fiber is build on Fasthttp and it use the same method to convert bytes to strings and vice-versa. https://github.com/valyala/fasthttp/blob/master/bytesconv.go#L332

So changing this won't matter since it's still being used by the fasthttp engine. I think adding the // #nosec G103 and a description should be fine 👍

@Fenny Fenny closed this as completed Feb 3, 2020
koddr added a commit that referenced this issue Feb 19, 2020
Accumulative update @ 19 Feb 2020
koddr added a commit that referenced this issue Apr 5, 2020
Accumulative update @ 05 Apr 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants