课程: Secure Coding in Go

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Linters

Linters

- [Instructor] We humans are forgetful and lazy. Everything you can automate, you should. When it comes to security, there are few options for automations. Gosec is a linter that will run your code and will find security issues. Let's see an example. So here is our code. We have a main function. We get the URL from the command line, and then we do a get for that URL, check the status code, read the data, and print out how many bytes there are. So now I can run gosec. And I tell it to run on the current directory and all the subdirectory. And it found one security problem, which is, we are getting a URL from a variable, which means that an attacker can persuade us to go to a malicious URL with our server credentials. It didn't catch everything. We also read the whole data into memory, and this is something that gosec did not catch. Remember that bugs can cause security issues as well. You can use staticcheck or…

内容