Commit 2737fba
chore: fix gosec warnings via ignore annotations in comments (#1770)
## What kind of change does this PR introduce?
Fix to gosec warnings so builds can complete.
## What is the current behavior?
The gosec checks are halting builds.
## What is the new behavior?
The gosec checks are passing.
## Additional context
I didn't see any warnings that led to real vulnerabilities / security
issues.
That said long term it may be worth adding some defensive bounds checks
for a couple of the integer overflow warnings, just to future proof us
age the code ages. Given that we allow supabase users to write to the
database, not sure we can guarantee a user doesn't provide a
bring-your-own-hash singup flow or something like that. Unbound
allocations are a prime target for DoS attacks.
For the nonce issues, neither is was real issue. Open is not "fixable,
see gosec issue [#1211](securego/gosec#1211).
For Seal I tried:
```
nonce := make([]byte, cipher.NonceSize())
if _, err := rand.Read(nonce); err != nil {
panic(err)
}
es := EncryptedString{
KeyID: keyID,
Algorithm: "aes-gcm-hkdf",
Nonce: nonce,
}
es.Data = cipher.Seal(nil, es.Nonce, data, nil)
```
But it then considers es.Nonce to be stored / hardcoded. The only fix I
could get to work was:
```Go
nonce := make([]byte, cipher.NonceSize())
if _, err := rand.Read(nonce); err != nil {
panic(err)
}
es := EncryptedString{
KeyID: keyID,
Algorithm: "aes-gcm-hkdf",
Nonce: nonce,
Data: cipher.Seal(nil, nonce, data, nil),
}
```
It seems the gosec tool requires using `rand.Read`. I changed the
`cipher.NonceSize()` back to `12` (just in case it a numerical constant
for a reason) and it started failing again. I think it also checks that
cipher.NonceSize() is used as well, just doesn't report that. I
ultimately decided to ignore this so there was no changes to crypto
functions given the existing code is correct.
Co-authored-by: Chris Stockton <[email protected]>1 parent 907ef22 commit 2737fba
File tree
6 files changed
+13
-12
lines changed- internal
- api
- crypto
- models
6 files changed
+13
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
718 | 718 | | |
719 | 719 | | |
720 | 720 | | |
721 | | - | |
| 721 | + | |
722 | 722 | | |
723 | 723 | | |
724 | 724 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
| 115 | + | |
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
206 | | - | |
| 206 | + | |
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
| 144 | + | |
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
160 | | - | |
| 160 | + | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
| 163 | + | |
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
159 | | - | |
160 | | - | |
| 159 | + | |
| 160 | + | |
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
9 | | - | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
111 | 112 | | |
112 | 113 | | |
113 | 114 | | |
114 | | - | |
| 115 | + | |
115 | 116 | | |
116 | 117 | | |
117 | 118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
683 | 683 | | |
684 | 684 | | |
685 | 685 | | |
686 | | - | |
687 | | - | |
| 686 | + | |
| 687 | + | |
688 | 688 | | |
689 | 689 | | |
690 | 690 | | |
| |||
0 commit comments