课程: Secure Coding in Go

今天就学习课程吧!

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

Size limiting

Size limiting

- [Instructor] Say you have an HTTP handler that is reading the data from a request and then doing something with it, let's say saving it in a database. It returns, how many bytes were stored? Let's run this code. So Run, Run Without Debugging. Let's view the Debug Console, to see if the server is running. I have a file with the first thousand digits of pi and I can send it to the server. So curl [email protected] https://localhost:8080, and then log. And then we have all of these bytes stored, but an attacker might decide to send you a hundred gigabytes file, which will exhaust the server memory and will crush it. In the standard library, we have an IO limit with it. It gets a reader and the number of bytes to read from it. You can use that to limit the amount of data you are reading. So let's copy the fix and have a look. So now we are defining the maximum size and the long handler is using the LimitReader with the…

内容