Skip to content

Commit 48b1c93

Browse files
Prevent code injection via template expansion
Fixes https://docs.zizmor.sh/audits/#template-injection warnings
1 parent 2bc71bd commit 48b1c93

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

.github/actions/maven-central-user-token/action.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ runs:
1212
steps:
1313
- shell: bash
1414
run: |
15-
USER_TOKEN=$(printf "${{ inputs.username }}:${{ inputs.password }}" | base64)
15+
USER_TOKEN=$(printf "${USERNAME}:${PASSWORD}" | base64)
1616
echo "::add-mask::$USER_TOKEN"
1717
echo "MAVEN_CENTRAL_USER_TOKEN=$USER_TOKEN" >> $GITHUB_ENV
18+
env:
19+
USERNAME: ${{ inputs.username }}
20+
PASSWORD: ${{ inputs.password }}

.github/workflows/release.yml

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ env:
2121
DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
2222
STAGING_REPO_URL: https://central.sonatype.com/api/v1/publisher/deployment/${{ inputs.deploymentId }}/download
2323
RELEASE_TAG: r${{ inputs.releaseVersion }}
24+
RELEASE_VERSION: ${{ inputs.releaseVersion }}
2425

2526
jobs:
2627

@@ -47,7 +48,7 @@ jobs:
4748
run: |
4849
curl --silent --fail --location --output /tmp/reference.jar \
4950
--header "Authorization: Bearer $MAVEN_CENTRAL_USER_TOKEN" \
50-
"${{ env.STAGING_REPO_URL }}/org/junit/jupiter/junit-jupiter-api/${{ inputs.releaseVersion }}/junit-jupiter-api-${{ inputs.releaseVersion }}.jar"
51+
"${STAGING_REPO_URL}/org/junit/jupiter/junit-jupiter-api/${RELEASE_VERSION}/junit-jupiter-api-${RELEASE_VERSION}.jar"
5152
sudo apt-get update && sudo apt-get install --yes jc
5253
unzip -c /tmp/reference.jar META-INF/MANIFEST.MF | jc --jar-manifest | jq '.[0]' > /tmp/manifest.json
5354
echo "createdBy=$(jq --raw-output .Created_By /tmp/manifest.json)" >> "$GITHUB_OUTPUT"
@@ -95,15 +96,15 @@ jobs:
9596
distribution: temurin
9697
- uses: sbt/setup-sbt@f20dc1bc1f8be605c44ffbcec6f17f708a4af9d1 # v1.1.12
9798
- name: Update JUnit dependencies in examples
98-
run: java src/Updater.java ${{ inputs.releaseVersion }}
99+
run: java src/Updater.java ${RELEASE_VERSION}
99100
working-directory: junit-examples
100101
- name: Prepare Maven Central user token
101102
uses: ./junit-framework/.github/actions/maven-central-user-token
102103
with:
103104
username: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
104105
password: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
105106
- name: Inject staging repository URL
106-
run: java src/StagingRepoInjector.java ${{ env.STAGING_REPO_URL }}
107+
run: java src/StagingRepoInjector.java ${STAGING_REPO_URL}
107108
working-directory: junit-examples
108109
- name: Build examples
109110
run: java src/Builder.java --exclude=junit-jupiter-starter-bazel,junit-jupiter-starter-sbt
@@ -123,6 +124,7 @@ jobs:
123124
with:
124125
result-encoding: string
125126
script: |
127+
const releaseVersion = process.env.RELEASE_VERSION;
126128
const query = `
127129
query ($owner: String!, $repo: String!, $title: String!) {
128130
repository(owner: $owner, name: $repo) {
@@ -139,14 +141,14 @@ jobs:
139141
const {repository} = await github.graphql(query, {
140142
owner: context.repo.owner,
141143
repo: context.repo.repo,
142-
title: "${{ inputs.releaseVersion }}"
144+
title: releaseVersion
143145
});
144-
const [milestone] = repository.milestones.nodes.filter(it => it.title === "${{ inputs.releaseVersion }}")
146+
const [milestone] = repository.milestones.nodes.filter(it => it.title === releaseVersion)
145147
if (!milestone) {
146-
throw new Error('Milestone "${{ inputs.releaseVersion }}" not found');
148+
throw new Error(`Milestone "${releaseVersion}" not found`);
147149
}
148150
if (milestone.openIssueCount > 0) {
149-
throw new Error(`Milestone "${{ inputs.releaseVersion }}" has ${milestone.openIssueCount} open issue(s)`);
151+
throw new Error(`Milestone "${releaseVersion}" has ${milestone.openIssueCount} open issue(s)`);
150152
}
151153
const requestBody = {
152154
owner: context.repo.owner,
@@ -228,14 +230,16 @@ jobs:
228230
id: pagesDeployment
229231
timeout-minutes: 20
230232
run: |
231-
URL="https://docs.junit.org/${{ inputs.releaseVersion }}/user-guide/junit-user-guide-${{ inputs.releaseVersion }}.pdf"
233+
URL="https://docs.junit.org/${RELEASE_VERSION}/user-guide/junit-user-guide-${RELEASE_VERSION}.pdf"
232234
./.github/scripts/waitForUrl.sh "$URL"
233235
echo "pdfUrl=$URL" >> "$GITHUB_OUTPUT"
234236
- name: Verify integrity of PDF version of User Guide
235237
if: ${{ inputs.dryRun == false }}
236238
run: |
237-
curl --silent --fail --location --output /tmp/junit-user-guide.pdf "${{ steps.pagesDeployment.outputs.pdfUrl }}"
239+
curl --silent --fail --location --output /tmp/junit-user-guide.pdf "${PDF_URL}"
238240
pdfinfo /tmp/junit-user-guide.pdf
241+
env:
242+
PDF_URL: ${{ steps.pagesDeployment.outputs.pdfUrl }}
239243

240244
update_examples:
241245
name: Update examples
@@ -257,26 +261,26 @@ jobs:
257261
distribution: temurin
258262
- uses: sbt/setup-sbt@f20dc1bc1f8be605c44ffbcec6f17f708a4af9d1 # v1.1.12
259263
- name: Update JUnit dependencies in examples
260-
run: java src/Updater.java ${{ inputs.releaseVersion }}
264+
run: java src/Updater.java ${RELEASE_VERSION}
261265
- name: Build examples
262266
if: ${{ inputs.dryRun == false }}
263267
run: java src/Builder.java
264268
- name: Create release branch
265269
run: |
266270
git config user.name "JUnit Team"
267271
git config user.email "[email protected]"
268-
git switch -c "${{ env.RELEASE_TAG }}"
272+
git switch -c "${RELEASE_TAG}"
269273
git status
270-
git commit -a -m "Use ${{ inputs.releaseVersion }}"
274+
git commit -a -m "Use ${RELEASE_VERSION}"
271275
- name: Push release branch
272276
if: ${{ inputs.dryRun == false }}
273277
run: |
274-
git push origin "${{ env.RELEASE_TAG }}"
278+
git push origin "${RELEASE_TAG}"
275279
- name: Update main branch (only for GA releases)
276280
if: ${{ inputs.dryRun == false && !contains(inputs.releaseVersion, '-') }}
277281
run: |
278282
git switch main
279-
git merge --ff-only "${{ env.RELEASE_TAG }}"
283+
git merge --ff-only "${RELEASE_TAG}"
280284
git push origin main
281285
282286
create_github_release:
@@ -291,7 +295,7 @@ jobs:
291295
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
292296
with:
293297
script: |
294-
const releaseVersion = "${{ inputs.releaseVersion }}";
298+
const releaseVersion = process.env.RELEASE_VERSION;
295299
const requestBody = {
296300
owner: context.repo.owner,
297301
repo: context.repo.repo,

0 commit comments

Comments
 (0)