Skip to content
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

✨ Support for detecting choco installer without required hash #1810

Merged
merged 6 commits into from Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion checks/pinned_dependencies_test.go
Expand Up @@ -245,7 +245,7 @@ func TestGithubWorkflowPkgManagerPinning(t *testing.T) {
expected: scut.TestReturn{
Error: nil,
Score: checker.MinResultScore,
NumberOfWarn: 26,
NumberOfWarn: 27,
NumberOfInfo: 0,
NumberOfDebug: 0,
},
Expand Down
48 changes: 48 additions & 0 deletions checks/shell_download_validate.go
Expand Up @@ -575,6 +575,42 @@ func isPipUnpinnedDownload(cmd []string) bool {
return false
}

func isChocoUnpinnedDownload(cmd []string) bool {
Alan-Jowett marked this conversation as resolved.
Show resolved Hide resolved
// Install command is in the form 'choco install ...'
if len(cmd) < 2 {
return false
}

if !isBinaryName("choco", cmd[0]) && !isBinaryName("choco.exe", cmd[0]) {
return false
}

if !strings.EqualFold(cmd[1], "install") {
return false
}

// If this is an install command, then some variant of requirechecksum must be present.
for i := 1; i < len(cmd); i++ {
parts := strings.Split(cmd[i], "=")
if len(parts) == 0 {
continue
}

str := parts[0]

switch {
laurentsimon marked this conversation as resolved.
Show resolved Hide resolved
case strings.EqualFold(str, "--requirechecksum"):
return false
case strings.EqualFold(str, "--requirechecksums"):
return false
case strings.EqualFold(str, "--require-checksums"):
return false
}
}

return true
}

func isUnpinnedPakageManagerDownload(startLine, endLine uint, node syntax.Node,
cmd, pathfn string, dl checker.DetailLogger,
) bool {
Expand Down Expand Up @@ -629,6 +665,18 @@ func isUnpinnedPakageManagerDownload(startLine, endLine uint, node syntax.Node,
return true
}

// Choco install.
if isChocoUnpinnedDownload(c) {
dl.Warn(&checker.LogMessage{
Path: pathfn,
Type: checker.FileTypeSource,
Offset: startLine,
EndOffset: endLine,
Snippet: cmd,
Text: "choco installation not pinned by hash",
})
return true
}
// TODO(laurent): add other package managers.

return false
Expand Down
Expand Up @@ -98,3 +98,11 @@ jobs:
run: python -m pip install 'some-pkg>1.2.3'
- name:
run: pip3 install -r bla-requirements.txt --require-hashes && pip3 install --require-hashes -r bla-requirements.txt
- name:
run: choco install 'some-package'
- name:
run: choco install --requirechecksum 'some-package'
- name:
run: choco install --requirechecksums 'some-package'
- name:
run: choco install --require-checksums 'some-package'