Skip to content

Wip - #193

Draft
Gérald Barré (geraldbarre-workleap) wants to merge 6 commits into
mainfrom
wip
Draft

Wip#193
Gérald Barré (geraldbarre-workleap) wants to merge 6 commits into
mainfrom
wip

Conversation

@geraldbarre-workleap

Copy link
Copy Markdown
Contributor

No description provided.

$ErrorActionPreference = "Stop"
$PSNativeCommandUseErrorActionPreference = $true

Import-Module "${{ github.action_path }}/RequiredChecksPolicy.psm1" -Force

Check warning

Code scanning / CodeQL

Code injection Medium

Potential code injection in
${ github.action_path }
, which may be controlled by an external user.

Copilot Autofix

AI 6 months ago

In general, to fix code injection warnings in GitHub Actions, untrusted or potentially untrusted values from expressions (${{ ... }}) should not be embedded directly in script bodies. Instead, assign them to environment variables via the env: block and then read them using the shell’s native variable syntax (e.g., $ENV:VAR in PowerShell, $VAR in bash). This prevents expression syntax from being evaluated in places where it could be interpreted as code.

For this specific case, we only need to adjust how github.action_path is passed into the PowerShell script. We will:

  • Add a new environment variable (e.g., CI_ACTION_PATH) in the env: block of the composite action step, assigned from ${{ github.action_path }}.
  • Update the Import-Module command to use $env:CI_ACTION_PATH instead of interpolating ${{ github.action_path }} directly in the script.

This preserves the existing behavior (importing RequiredChecksPolicy.psm1 from the action’s directory) while removing direct ${{ ... }} usage from inside the run: script. The only file to change is .github/actions/required-checks-policy/action.yml, lines around the env: block and the Import-Module call; no new imports or additional methods are needed.

Suggested changeset 1
.github/actions/required-checks-policy/action.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/actions/required-checks-policy/action.yml b/.github/actions/required-checks-policy/action.yml
--- a/.github/actions/required-checks-policy/action.yml
+++ b/.github/actions/required-checks-policy/action.yml
@@ -33,11 +33,12 @@
               CI_TIMEOUT_MINUTES_QUEUED_CHECKS: ${{ inputs.timeout-minutes-queued-checks }}
               CI_TIMEOUT_MINUTES_CREATED_CHECKS: ${{ inputs.timeout-minutes-created-checks }}
               REPOSITORY_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
+              CI_ACTION_PATH: ${{ github.action_path }}
           run: |
               $ErrorActionPreference = "Stop"
               $PSNativeCommandUseErrorActionPreference = $true
 
-              Import-Module "${{ github.action_path }}/RequiredChecksPolicy.psm1" -Force
+              Import-Module "$env:CI_ACTION_PATH/RequiredChecksPolicy.psm1" -Force
 
               $refs = Resolve-Refs `
                   -CommitId $env:GITHUB_SHA `
EOF
@@ -33,11 +33,12 @@
CI_TIMEOUT_MINUTES_QUEUED_CHECKS: ${{ inputs.timeout-minutes-queued-checks }}
CI_TIMEOUT_MINUTES_CREATED_CHECKS: ${{ inputs.timeout-minutes-created-checks }}
REPOSITORY_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
CI_ACTION_PATH: ${{ github.action_path }}
run: |
$ErrorActionPreference = "Stop"
$PSNativeCommandUseErrorActionPreference = $true

Import-Module "${{ github.action_path }}/RequiredChecksPolicy.psm1" -Force
Import-Module "$env:CI_ACTION_PATH/RequiredChecksPolicy.psm1" -Force

$refs = Resolve-Refs `
-CommitId $env:GITHUB_SHA `
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +16 to +35
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v5
- name: Run Pester tests
shell: pwsh
run: |
$config = New-PesterConfiguration
$config.Run.Path = ".github/actions/required-checks-policy/RequiredChecksPolicy.Tests.ps1"
$config.Output.Verbosity = "Detailed"
$config.TestResult.Enabled = $true
$config.TestResult.OutputFormat = "JUnitXml"
$config.TestResult.OutputPath = "test-results.xml"
Invoke-Pester -Configuration $config
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: pester-results
path: test-results.xml

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 6 months ago

In general, fix this by explicitly declaring a permissions block that grants only the minimal GITHUB_TOKEN permissions the workflow needs. You can add this either at the top level of the workflow (so it applies to all jobs that don’t override it) or under a specific job. For this workflow, the steps only need read access to repository contents (for actions/checkout) and do not need to write to the repo or to issues/PRs, so contents: read is sufficient.

The best minimal change without altering functionality is to add a root-level permissions block just below the name (and before on:) in .github/workflows/~internal-required-checks-policy.yml:

permissions:
  contents: read

This sets the default GITHUB_TOKEN permission to read-only for repository contents for all jobs in this workflow, leaving artifact uploads unaffected because they do not require additional repo write scopes. No new imports or external dependencies are needed; permissions is a native GitHub Actions workflow key.

Suggested changeset 1
.github/workflows/~internal-required-checks-policy.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/~internal-required-checks-policy.yml b/.github/workflows/~internal-required-checks-policy.yml
--- a/.github/workflows/~internal-required-checks-policy.yml
+++ b/.github/workflows/~internal-required-checks-policy.yml
@@ -1,5 +1,8 @@
 name: Internal - Test Required Checks Policy
 
+permissions:
+    contents: read
+
 on:
     push:
         branches: [main]
EOF
@@ -1,5 +1,8 @@
name: Internal - Test Required Checks Policy

permissions:
contents: read

on:
push:
branches: [main]
Copilot is powered by AI and may make mistakes. Always verify output.
Gérald Barré added 3 commits March 10, 2026 15:06
Cloning an empty bare repo may not configure remote.origin.fetch,
causing git fetch to skip creating refs/remotes/origin/* tracking refs.
Cloning an empty bare repo does not set up remote tracking refs reliably
across git versions. Instead, create a populated origin repo first, then
clone it so refs/remotes/origin/* are properly created.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants