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

Use of net/http's ListenAndServe function has no support for setting timeouts #41

Closed
uzaxirr opened this issue Jan 3, 2023 · 3 comments
Assignees

Comments

@uzaxirr
Copy link
Member

uzaxirr commented Jan 3, 2023

Description

HTTP timeouts are necessary to expire inactive connections and failing to do so might make the application vulnerable to attacks like slowloris which work by sending data very slow, which in case of no timeout will keep the connection active eventually leading to a denial-of-service (DoS) attack.

Occurrences

There is 1 occurrence of this issue in the repository.

See all occurrences on DeepSource → deepsource.io/gh/ZeStream/zestream-server/issue/GO-S2114/occurrences/

Screenshot 2023-01-03 at 10 42 12 AM

Solution

A possible solution could be

server := &http.Server{
    Addr:         port,
    ReadTimeout:  time.Duration(timeout) * time.Second,
    WriteTimeout: time.Duration(timeout) * time.Second,
}

err := server.ListenAndServe()
@vivek378521
Copy link
Contributor

Have made some changes to the main.go file
Please review: #45

Do suggest if any more changes need to be made @uzaxirr

@vivek378521
Copy link
Contributor

vivek378521 commented Jan 3, 2023

@uzaxirr there was some rebase issue so resolved your comments and created a new PR: #46

Apologies for the older PR. have also attached the test screenshot to the PR

@uzaxirr
Copy link
Member Author

uzaxirr commented Jan 5, 2023

closed via #46

@uzaxirr uzaxirr closed this as completed Jan 5, 2023
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