Live data from Hacker News

Go Language – Web Application Secure Coding Practices

checkmarx.gitbooks.io

41–50 of 55 posts

Re: Go Language – Web Application Secure Coding Practices

#41
post #27

Don't read it, always start with using a good framework. It will do everything for you

Hi homakov, given your experience with security, could you please expand on _why_ we should not this particular guide? I do understand why we should start with using a good framework, and I have so far felt that reading guides also help us understand things to be aware of.

Re: Go Language – Web Application Secure Coding Practices

#42
post #13

Earlier quoted context omitted.

> You must sanitize ALL user input even if you don't think you're going to render it on a web page. I'm not able to make sense of this. Sanitize it for what context? SQL? JSON? HTML? Inclusion as a command-line argument? All of these, and hope that sanitizing it for one context doesn't un-sanitize it for others?

Context here means the context of the output page. Usually this means the HTML context. Different sanitization is needed depending on _where_ in the HTML document the input is used. For instance, if the input is used in between HTML tags (let's say $foo is user input in this PHP example): ... Here, the input that you need to transition to JavaScript execution is a alert(1) . Therefore, to correctly sanitize this, you…

[deleted]

Re: Go Language – Web Application Secure Coding Practices

#43
post #13

Earlier quoted context omitted.

> You must sanitize ALL user input even if you don't think you're going to render it on a web page. I'm not able to make sense of this. Sanitize it for what context? SQL? JSON? HTML? Inclusion as a command-line argument? All of these, and hope that sanitizing it for one context doesn't un-sanitize it for others?

Context here means the context of the output page. Usually this means the HTML context. Different sanitization is needed depending on _where_ in the HTML document the input is used. For instance, if the input is used in between HTML tags (let's say $foo is user input in this PHP example): ... Here, the input that you need to transition to JavaScript execution is a alert(1) . Therefore, to correctly sanitize this, you…

[deleted]

Re: Go Language – Web Application Secure Coding Practices

#44
post #5

Theres a whole section on stored procedures - it was my understanding that the database/sql package in the sodlib didn't support stored procedures (something to do with multiple rows or output var support)

The database/sql package is just bad anyway. The idea is sound but the execution is catastrophic and not many thought went into the design of this package. This is especially true with Postgresql where you are kind of forced to use db.Query instead of db.Exec on inserts or updates. Go std lib have a lot of issues like these. On the top of my head the log package and the flags package are pretty useless in real world apps.

Re: Go Language – Web Application Secure Coding Practices

#45
post #2

Go has also an amazing static-analysis tool, vet, that is not mentioned in the article: https://golang.org/cmd/vet/ It can find printf-format errors, invalid shifts, unreachable code, etc. Even though go vet is very helpful, it is sometimes scary that the compiler allows to build such incorrect code. For instance: https://play.golang.org/p/2AVHUt5Wcf

That's a weird criticism to read when most of the time people moan about the Go compiler being too strict for failing to compile code with errors that other compilers might only warn or even if ignore.

Go does already have one of the strictest compilers (by default) out there. But it is pretty typical for a great many language frameworks to support optional additional strictness. Eg "use strict" in Perl or the gcc flags of which I cannot recall off hand. I see God's vet as akin to those. ie there when you need it but keeps out of your way when you just need to get some prototyping done.

Re: Go Language – Web Application Secure Coding Practices

#46
post #10
post #2

Go has also an amazing static-analysis tool, vet, that is not mentioned in the article: https://golang.org/cmd/vet/ It can find printf-format errors, invalid shifts, unreachable code, etc. Even though go vet is very helpful, it is sometimes scary that the compiler allows to build such incorrect code. For instance: https://play.golang.org/p/2AVHUt5Wcf

I'm not sure how `fmt.Printf("%s\n", i) // invalid type` is really that "scary". Expecting the compiler to introspect that Printf's `...interface{}` argument's first value is incorrect, even though `i` does fulfill the stated parameter's type, is a FAR more scary thought.

The important thing here is, that fmt.Printf is just a function which takes a string and a variable amount of interface{} parameters. There is nothing in the language spec which creates a type correlation. the "%s" denotes a string parameter to print is solely some inner working of the Printf function. Yes, you can special case fmt.Printf, as some compilers do, but given the standard go vet tool, I rather think it belongs there than into the compiler, which, following the Go philosophy, exactly understands the Go language and precisely compiles that.

Re: Go Language – Web Application Secure Coding Practices

#47
post #2

Go has also an amazing static-analysis tool, vet, that is not mentioned in the article: https://golang.org/cmd/vet/ It can find printf-format errors, invalid shifts, unreachable code, etc. Even though go vet is very helpful, it is sometimes scary that the compiler allows to build such incorrect code. For instance: https://play.golang.org/p/2AVHUt5Wcf

What by the language spec makes your code incorrect? The only question is, does the compiler generate a constant call to print "false"? But this would be an optimization, not a correctness question.

Re: Go Language – Web Application Secure Coding Practices

#48
post #23

Earlier quoted context omitted.

To be fair to the person you're responding to, do you think people looking for copypasta are going to check the fine print? The code sample in question is in no way clearly labeled as being problematic, and a tiny statement buried in a large body of text does not change that fact.

To be fair to the person you are responding to, I don't think copypasta developers are going to create secure applications anyway.

Which is exactly why the only copy-paste-able code should be secure by default. Much like the idea behind the existence of NaCl, the easiest thing to do should be the correct thing to do.

Re: Go Language – Web Application Secure Coding Practices

#49
post #15

Earlier quoted context omitted.

Yes, really. Otherwise, you must take extra care not to reflect any input data back in any response to the user, whether it's in the HTML body or not. See: HTTP response splitting.

No, not really. In fact, you have it totally backwards: you're not supposed to sanitize all user input before storing it. Instead you're supposed to sanitize any user input before you output it back to your webpage. Even more so: it's the output that dictates what sanitization you should perform, not the input. You don't do input sanitization for HTML (for XSS etc) when you store your data in your DB. Instead you sho…

Also really it should be less about sanitising, more about escaping. If possible, the input should be stored essentially as-is.

Re: Go Language – Web Application Secure Coding Practices

#50
post #27

Don't read it, always start with using a good framework. It will do everything for you

Hi homakov, given your experience with security, could you please expand on _why_ we should not this particular guide? I do understand why we should start with using a good framework, and I have so far felt that reading guides also help us understand things to be aware of.

Given he got kind of famous for breaking GitHub using a Rails bug, I'm pretty sure he was being sarcastic.

For reference:

http://homakov.blogspot.fr/2012/03/how-to.html https://news.ycombinator.com/item?id=3663197

Post reply on HN