-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Git issue #5009 Asset cache can lead to denial of service if asset database is deleted -Fix #5050
Open
SudhanshuBawane
wants to merge
9
commits into
develop/6
Choose a base branch
from
sudhanshu#5009/DOS-fix
base: develop/6
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
928fc14
final
SudhanshuBawane 1518782
final_fix
SudhanshuBawane 18f450c
final
SudhanshuBawane 001844f
final
SudhanshuBawane 357ac9f
resolved
SudhanshuBawane d2a0d01
resolved
SudhanshuBawane ee21635
WIP
SudhanshuBawane 5441dbb
comments resolved
SudhanshuBawane fb8b8a8
comments resolved
SudhanshuBawane File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"errors" | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
archiver "github.com/mholt/archiver/v3" | ||
|
||
|
@@ -90,3 +91,14 @@ func sniffType(f io.ReadSeeker) (filetype_types.Type, error) { | |
|
||
return ft, nil | ||
} | ||
|
||
// Sudhanshu - CleanUp the SHA for the git issue 5009 fix. Making sure that in case of DOS when asset.db gets deleted it gets cleanUp so that asset can be re-downloded | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: no need to add your name and issue number :) |
||
|
||
func CleanUp(fullPath string) error { | ||
errorSHA := os.RemoveAll(fullPath) | ||
if errorSHA != nil { | ||
return errorSHA | ||
} | ||
return nil | ||
|
||
} |
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 |
---|---|---|
|
@@ -113,3 +113,33 @@ func TestExpandInvalidArchive(t *testing.T) { | |
t.Fail() | ||
} | ||
} | ||
|
||
// ---Test to check CleanUp | ||
func TestCleanUp(t *testing.T) { | ||
t.Parallel() | ||
|
||
// Create a temporary directory for testing | ||
tmpDir := t.TempDir() | ||
|
||
// Define the SHA and file name | ||
SHAName := "shaAsset.tar" | ||
SHAFilePath := filepath.Join(tmpDir, SHAName) | ||
|
||
// Create a dummy file inside the temporary directory | ||
SHAFile, err := os.Create(SHAFilePath) | ||
if err != nil { | ||
t.Fatalf("Failed to create dummy file: %v", err) | ||
} | ||
SHAFile.Close() | ||
|
||
// Call CleanUp with the SHA of the dummy file and the temporary directory | ||
err = CleanUp(SHAFilePath) | ||
if err != nil { | ||
t.Errorf("CleanUp returned an error: %v", err) | ||
} | ||
|
||
_, err = os.Stat(SHAFilePath) | ||
if !os.IsNotExist(err) { | ||
t.Errorf("CleanUp did not remove the dummy file as expected") | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This only tests os.RemoveAll and is therefore unnecessary |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if more context information such as the SHA and full path could be provided with the log message. You can use
WithFields
andWithError
.Additionally please use an explicit log level such as
Errorf
orWarnf
instead of using the genericPrintf
. In this case I believe warning would be an appropriate log level.You can see an example at
sensu-go/backend/pipeline/filter/legacy.go
Line 126 in 76c7a16