Repository: ossf/scorecard (Go)

Issue:
scorecard shouldn't complain about actions in the same repository
It's possible to reference actions that are kept in the same repository using `./path/to/dir`: https://docs.github.com/en/actions/learn-github-actions/finding-and-customizing-actions#referencing-an-action-in-the-same-repository-where-a-workflow-file-uses-the-action. I don't think scorecard should complain about them.


Discussion:
Great catch, thanks! Feel free to send a PR and cc me on it for approval.
see https://github.com/ossf/scorecard/pull/1357



Patch:
diff --git a/checks/pinned_dependencies.go b/checks/pinned_dependencies.go
index f637b6d394c..31dd3cbc995 100644
--- a/checks/pinned_dependencies.go
+++ b/checks/pinned_dependencies.go
@@ -606,6 +606,14 @@ func validateGitHubActionWorkflow(pathfn string, content []byte,
 				// Cannot check further, continue.
 				continue
 			}
+
+			// nolint:lll
+			// Check whether this is an action defined in the same repo,
+			// https://docs.github.com/en/actions/learn-github-actions/finding-and-customizing-actions#referencing-an-action-in-the-same-repository-where-a-workflow-file-uses-the-action.
+			if strings.HasPrefix(execAction.Uses.Value, "./") {
+				continue
+			}
+
 			// Ensure a hash at least as large as SHA1 is used (40 hex characters).
 			// Example: action-name@hash
 			match := hashRegex.Match([]byte(execAction.Uses.Value))


Test patch:
diff --git a/checks/pinned_dependencies_test.go b/checks/pinned_dependencies_test.go
index ca1a9da3c16..046687f6341 100644
--- a/checks/pinned_dependencies_test.go
+++ b/checks/pinned_dependencies_test.go
@@ -64,6 +64,17 @@ func TestGithubWorkflowPinning(t *testing.T) {
 				NumberOfDebug: 0,
 			},
 		},
+		{
+			name:     "Local action workflow",
+			filename: "./testdata/workflow-local-action.yaml",
+			expected: scut.TestReturn{
+				Error:         nil,
+				Score:         checker.MaxResultScore,
+				NumberOfWarn:  0,
+				NumberOfInfo:  2,
+				NumberOfDebug: 0,
+			},
+		},
 		{
 			name:     "Non-pinned workflow",
 			filename: "./testdata/workflow-not-pinned.yaml",
diff --git a/checks/testdata/workflow-local-action.yaml b/checks/testdata/workflow-local-action.yaml
new file mode 100644
index 00000000000..a8c68e88b70
--- /dev/null
+++ b/checks/testdata/workflow-local-action.yaml
@@ -0,0 +1,42 @@
+# Copyright 2021 Security Scorecard Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+on:
+  push:
+    paths:
+    - 'source/common/**'
+  pull_request:
+
+jobs:
+  CodeQL-Build:
+
+    strategy:
+      fail-fast: false
+
+    # CodeQL runs on ubuntu-latest and windows-latest
+    runs-on: ubuntu-latest
+
+    steps:
+    - name: Local step 1
+      uses: ./myaction/file
+      with:
+        fetch-depth: 2
+    - name: Checkout repository
+      uses: actions/checkout@daadedc81d5f9d3c06d2c92f49202a3cc2b919ba
+      with:
+        # We must fetch at least the immediate parents so that if this is
+        # a pull request then we can checkout the head.
+        fetch-depth: 2
+
+    - name: Local action 2
+      uses: ./myaction/file2
\ No newline at end of file