-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add ProtectOpenFile wrapping os.OpenFile
- Loading branch information
Showing
3 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# os | ||
|
||
This package provides a wrapper for [`os`](https://pkg.go.dev/os) protected by Waffle. | ||
It provides functions that wrap `os.ReadFile` and `os.WriteFile` to prevent directory traversal and access to sensitive files. | ||
|
||
# Usage | ||
|
||
When accessing a file, use the Waffle's file functions instead of `os`. | ||
|
||
```go | ||
import ( | ||
waffleOs "github.com/sitebatch/waffle-go/contrib/os" | ||
) | ||
|
||
// ProtectReadFile wraps os.ReadFile | ||
data, err := waffleOs.ProtectReadFile(ctx, "<filename>") | ||
|
||
// ProtectOpenFile wraps os.OpenFile | ||
f, err := waffleOs.ProtectOpenFile("notes.txt", os.O_RDWR|os.O_CREATE, 0644) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters