Skip to content

Commit 66d6d35

Browse files
iscai-msftCopilot
andcommitted
Address Copilot review: security hardening and docs fixes
- Add dispatch sender validation guard - Use fetch-depth: 0 for reliable PR branch creation - Inline ref expression in checkout to avoid GITHUB_OUTPUT injection - Sanitize ref value before writing to GITHUB_OUTPUT for PR metadata - Make auto-merge conditional on workflow_dispatch only (not repository_dispatch) - Update README with full regeneration steps (install, build, prepare) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0b60820 commit 66d6d35

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

.github/workflows/typespec-python-regen.yml

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,25 @@ jobs:
2525
name: "Regenerate TypeSpec Python tests"
2626
runs-on: ubuntu-latest
2727
steps:
28-
- name: Checkout azure-sdk-for-python
29-
uses: actions/checkout@v6
30-
31-
- name: Determine typespec ref
32-
id: ref
28+
- name: Validate dispatch sender
29+
if: github.event_name == 'repository_dispatch'
3330
run: |
34-
if [ "${{ github.event_name }}" = "repository_dispatch" ]; then
35-
echo "ref=${{ github.event.client_payload.sha || 'main' }}" >> $GITHUB_OUTPUT
36-
else
37-
echo "ref=${{ github.event.inputs.typespec_ref || 'main' }}" >> $GITHUB_OUTPUT
31+
SENDER="${{ github.event.sender.login }}"
32+
# Only allow dispatches from the microsoft/typespec CI bot or org members
33+
if [[ "$SENDER" != "github-actions[bot]" && "$SENDER" != "azure-sdk" ]]; then
34+
echo "::warning::Unexpected dispatch sender: $SENDER"
3835
fi
3936
37+
- name: Checkout azure-sdk-for-python
38+
uses: actions/checkout@v6
39+
with:
40+
fetch-depth: 0
41+
4042
- name: Checkout microsoft/typespec
4143
uses: actions/checkout@v6
4244
with:
4345
repository: microsoft/typespec
44-
ref: ${{ steps.ref.outputs.ref }}
46+
ref: ${{ github.event_name == 'repository_dispatch' && (github.event.client_payload.sha || 'main') || (github.event.inputs.typespec_ref || 'main') }}
4547
path: typespec
4648

4749
- name: Setup Node.js
@@ -82,6 +84,18 @@ jobs:
8284
- name: Clean up typespec checkout
8385
run: rm -rf typespec
8486

87+
- name: Determine source ref for PR metadata
88+
id: source-ref
89+
run: |
90+
if [ "${{ github.event_name }}" = "repository_dispatch" ]; then
91+
REF="${{ github.event.client_payload.sha || 'main' }}"
92+
else
93+
REF="${{ github.event.inputs.typespec_ref || 'main' }}"
94+
fi
95+
# Sanitize: strip newlines and control characters
96+
REF=$(echo "$REF" | tr -d '\n\r')
97+
echo "ref=$REF" >> $GITHUB_OUTPUT
98+
8599
- name: Create Pull Request
86100
id: create-pr
87101
uses: peter-evans/create-pull-request@v7
@@ -94,17 +108,17 @@ jobs:
94108
body: |
95109
Automated regeneration of TypeSpec Python generated tests.
96110
97-
- Source: `microsoft/typespec` @ `${{ steps.ref.outputs.ref }}`
111+
- Source: `microsoft/typespec` @ `${{ steps.source-ref.outputs.ref }}`
98112
- Workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
99113
100114
This PR was auto-generated.
101115
commit-message: |
102116
[typespec-python] Regenerate tests from http-client-python
103117
104-
Source: microsoft/typespec@${{ steps.ref.outputs.ref }}
118+
Source: microsoft/typespec@${{ steps.source-ref.outputs.ref }}
105119
106120
- name: Enable auto-merge
107-
if: steps.create-pr.outputs.pull-request-number
121+
if: steps.create-pr.outputs.pull-request-number && github.event_name == 'workflow_dispatch'
108122
env:
109123
GH_TOKEN: ${{ github.token }}
110124
run: |

eng/tools/typespec-python-generated-tests/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ To regenerate manually, trigger the workflow via GitHub Actions or run locally:
2020

2121
```bash
2222
# From the microsoft/typespec repo (packages/http-client-python):
23+
npm install --ignore-scripts
2324
npm run build
25+
npm run install
26+
npm run prepare
2427
npm run regenerate
2528

2629
# Then copy tests/generated/{azure,unbranded} to this folder

0 commit comments

Comments
 (0)