Proposal: Make Go2 better implement the Object-capability model for security. #23157
Description
UPDATE
We're forking to HOG-lang. https://github.com/HogLang/hog
Original proposal and motivation
This proposal is a combination of three proposals to evolve Golang towards a more secure language that is robust against malicious dependencies.
Design principle: Implement the object-capability model
- Read-only slices
- Secure modules w/ the const-mutable type
- Pointerized structs
0. Read-only slices
Slices are used everywhere in Golang, but there's no native language feature to help with safety. It's not always immediately obvious whether it's safe to pass a slice, or whether that slice needs to be copied before being passed in or returned. You need to think about the performance tradeoffs of copying or not, and often that blinds you to the concern of security/mutability.
Read the read-only slices proposal here.
It's an extension to Brad's original proposal, and it introduces any
and readonly
modifiers to slices.
1. Secure modules w/ the const-mutable type
With most module-level vars today, it's clear that you're not really supposed to update them. Or rather, it wouldn't be secure to allow arbitrary code to update them. For example, see the var in https://golang.org/pkg/crypto/rand/ : Reader could be replaced with something bad by malicious code, and the next user of crypto/rand.Reader wouldn't know.
See the const-mutable proposal.
2. Pointerized structs
The same problem exists for pointers as for slices. One could argue that the coder should keep fields private and just use getters and setters for permissions, but public/private (exposed/unexposed) fields are not really used today in the security context of malicious code. You expose a field because the user might need read access to it and it's convenient to expose rather than writing a getter, or, because the user is expected to write to the field in a non-malicious way.
The proposed solution is to support structs that are always passed by reference.
Read the pointerized struct proposal here.
More discussions and proposals
Several people have brought up other proposals worth mentioning here. I'll continue to compile these proposals and link to them from here.
- @randall77 brought up the issue of data-races.
- @jba proposed Go2 read-only types.
- @wora proposed pure modules aka "gocap".
UPDATE
We're forking to HOG-lang. https://github.com/HogLang/hog