Skip to content

Commit c5e9d08

Browse files
authored
Merge pull request #366 from hashicorp/eastebry/update-readme
Adding security sections to the README
2 parents f710948 + d4c5010 commit c5e9d08

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ $ go-getter github.com/foo/bar ./foo
4545

4646
The command is useful for verifying URL structures.
4747

48+
## Security
49+
Fetching resources from user-supplied URLs is an inherently dangerous operation and may
50+
leave your application vulnerable to [server side request forgery](https://owasp.org/www-community/attacks/Server_Side_Request_Forgery),
51+
[path traversal](https://owasp.org/www-community/attacks/Path_Traversal), [denial of service](https://owasp.org/www-community/attacks/Denial_of_Service)
52+
or other security flaws.
53+
54+
go-getter contains mitigations for some of these security issues, but should still be used with
55+
caution in security-critical contexts. See the available [security options](#Security-Options) that
56+
can be configured to mitigate some of these risks.
4857
## URL Format
4958

5059
go-getter uses a single string URL as input to download from a variety of
@@ -361,3 +370,79 @@ In order to access to GCS, authentication credentials should be provided. More i
361370
#### GCS Testing
362371

363372
The tests for `get_gcs.go` require you to have GCP credentials set in your environment. These credentials can have any level of permissions to any project, they just need to exist. This means setting `GOOGLE_APPLICATION_CREDENTIALS="~/path/to/credentials.json"` or `GOOGLE_CREDENTIALS="{stringified-credentials-json}"`. Due to this configuration, `get_gcs_test.go` will fail for external contributors in CircleCI.
373+
374+
375+
### Security Options
376+
377+
**Disable Symlinks**
378+
379+
In your getter client config, we recommend using the `DisableSymlinks` option,
380+
which prevents writing through or copying from symlinks (which may point outside the directory).
381+
382+
```go
383+
client := getter.Client{
384+
// This will prevent copying or writing files through symlinks
385+
DisableSymlinks: true,
386+
}
387+
```
388+
389+
**Disable or Limit `X-Terraform-Get`**
390+
391+
Go-Getter supports arbitrary redirects via the `X-Terraform-Get` header. This functionality
392+
exists to support [Terraform use cases](https://www.terraform.io/language/modules/sources#http-urls),
393+
but is likely not needed in most applications.
394+
395+
For code that uses the `HttpGetter`, add the following configuration options:
396+
397+
```go
398+
var httpGetter = &getter.HttpGetter{
399+
// Most clients should disable X-Terraform-Get
400+
// See the note below
401+
XTerraformGetDisabled: true,
402+
// Your software probably doesn’t rely on X-Terraform-Get, but
403+
// if it does, you should set the above field to false, plus
404+
// set XTerraformGet Limit to prevent endless redirects
405+
// XTerraformGetLimit: 10,
406+
}
407+
```
408+
409+
**Enforce Timeouts**
410+
411+
The `HttpGetter` supports timeouts and other resource-constraining configuration options. The `GitGetter` and `HgGetter`
412+
only support timeouts.
413+
414+
Configuration for the `HttpGetter`:
415+
416+
```go
417+
var httpGetter = &getter.HttpGetter{
418+
// Disable pre-fetch HEAD requests
419+
DoNotCheckHeadFirst: true,
420+
421+
// As an alternative to the above setting, you can
422+
// set a reasonable timeout for HEAD requests
423+
// HeadFirstTimeout: 10 * time.Second,
424+
425+
// Read timeout for HTTP operations
426+
ReadTimeout: 30 * time.Second,
427+
428+
// Set the maximum number of bytes
429+
// that can be read by the getter
430+
MaxBytes: 500000000, // 500 MB
431+
}
432+
```
433+
434+
For code that uses the `GitGetter` or `HgGetter`, set the `Timeout` option:
435+
```go
436+
var gitGetter = &getter.GitGetter{
437+
// Set a reasonable timeout for git operations
438+
Timeout: 5 * time.Minute,
439+
}
440+
```
441+
442+
```go
443+
var hgGetter = &getter.HgGetter{
444+
// Set a reasonable timeout for hg operations
445+
Timeout: 5 * time.Minute,
446+
}
447+
```
448+

0 commit comments

Comments
 (0)