-
Notifications
You must be signed in to change notification settings - Fork 4
fix(security)!: disable node scripts by default #717
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
Open
xnyo
wants to merge
4
commits into
main
Choose a base branch
from
giuseppe/node-pm-ignore-scripts
base: main
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 all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,98 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/grafana/plugin-ci-workflows/tests/act/internal/act" | ||
| "github.com/grafana/plugin-ci-workflows/tests/act/internal/workflow" | ||
| "github.com/grafana/plugin-ci-workflows/tests/act/internal/workflow/ci" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // TestInstallScripts verifies the "Configure package manager script policy" logic | ||
| // in the frontend action against the three real test plugins (npm, yarn, pnpm), | ||
| // with allow-scripts both true and false. | ||
| // | ||
| // TODO: add a simple-frontend-yarn-berry test plugin and cover the yarnBerry agent path, | ||
| // where --ignore-scripts is NOT appended to the CLI (Berry rejects it) and scripts are | ||
| // suppressed solely via the YARN_ENABLE_SCRIPTS env var. | ||
| func TestInstallScripts(t *testing.T) { | ||
| type testCase struct { | ||
| folder string | ||
| allowScripts bool | ||
| wantCmdContains string | ||
| wantCmdNotContains string | ||
| wantNPMIgnore bool | ||
| wantYarnDisable bool | ||
| } | ||
|
|
||
| for _, tc := range []testCase{ | ||
| {folder: "simple-frontend", allowScripts: false, wantCmdContains: "--ignore-scripts", wantNPMIgnore: true, wantYarnDisable: true}, | ||
| {folder: "simple-frontend-yarn", allowScripts: false, wantCmdContains: "--ignore-scripts", wantNPMIgnore: true, wantYarnDisable: true}, | ||
| {folder: "simple-frontend-pnpm", allowScripts: false, wantCmdContains: "--ignore-scripts", wantNPMIgnore: true, wantYarnDisable: true}, | ||
| {folder: "simple-frontend", allowScripts: true, wantCmdNotContains: "--ignore-scripts", wantNPMIgnore: false, wantYarnDisable: false}, | ||
| {folder: "simple-frontend-yarn", allowScripts: true, wantCmdNotContains: "--ignore-scripts", wantNPMIgnore: false, wantYarnDisable: false}, | ||
| {folder: "simple-frontend-pnpm", allowScripts: true, wantCmdNotContains: "--ignore-scripts", wantNPMIgnore: false, wantYarnDisable: false}, | ||
| } { | ||
| t.Run(fmt.Sprintf("%s/allow-scripts=%v", tc.folder, tc.allowScripts), func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| runner, err := act.NewRunner(t) | ||
| require.NoError(t, err) | ||
|
|
||
| wf, err := ci.NewWorkflow( | ||
| ci.WithWorkflowInputs(ci.WorkflowInputs{ | ||
| PluginDirectory: workflow.Input(filepath.Join("tests", tc.folder)), | ||
| DistArtifactsPrefix: workflow.Input(tc.folder + "-"), | ||
| RunPlaywright: workflow.Input(false), | ||
| NodePackageManagerAllowScripts: workflow.Input(tc.allowScripts), | ||
| }), | ||
| ci.MutateCIWorkflow().With( | ||
| workflow.WithOnlyOneJob(t, "test-and-build", true), | ||
| workflow.WithRemoveAllStepsAfter(t, "test-and-build", "frontend"), | ||
| ), | ||
| ) | ||
| require.NoError(t, err) | ||
|
|
||
| r, err := runner.Run(wf, act.NewPushEventPayload("main")) | ||
| require.NoError(t, err) | ||
| require.True(t, r.Success, "workflow should succeed") | ||
|
|
||
| var installCmdAnnotation *act.Annotation | ||
| for i, ann := range r.Annotations { | ||
| if ann.Level == act.AnnotationLevelDebug && strings.Contains(ann.Message, `msg="install-cmd"`) { | ||
| installCmdAnnotation = &r.Annotations[i] | ||
| break | ||
| } | ||
| } | ||
| require.NotNil(t, installCmdAnnotation, "install-cmd annotation should be present") | ||
| if tc.wantCmdContains != "" { | ||
| require.Contains(t, installCmdAnnotation.Message, tc.wantCmdContains) | ||
| } | ||
| if tc.wantCmdNotContains != "" { | ||
| require.NotContains(t, installCmdAnnotation.Message, tc.wantCmdNotContains) | ||
| } | ||
|
|
||
| npmIgnoreVal := "not-set" | ||
| if tc.wantNPMIgnore { | ||
| npmIgnoreVal = "true" | ||
| } | ||
| require.Contains(t, r.Annotations, act.Annotation{ | ||
| Level: act.AnnotationLevelDebug, | ||
| Message: fmt.Sprintf(`msg="npm-config-ignore-scripts" value=%s`, npmIgnoreVal), | ||
| }) | ||
|
|
||
| yarnVal := "not-set" | ||
| if tc.wantYarnDisable { | ||
| yarnVal = "false" | ||
| } | ||
| require.Contains(t, r.Annotations, act.Annotation{ | ||
| Level: act.AnnotationLevelDebug, | ||
| Message: fmt.Sprintf(`msg="yarn-enable-scripts" value=%s`, yarnVal), | ||
| }) | ||
| }) | ||
| } | ||
| } |
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.
cspell doesn't have any lifecycle scripts for install, so it's safe to always skip the, regardless of the value of
node-package-manager-allow-scripts