Skip to content

Commit 6901bc8

Browse files
authored
Merge pull request #11 from HewlettPackard/sanitize_title
Sanitize title in pr for auto-release
2 parents 6df3dcf + 896cdc8 commit 6901bc8

File tree

2 files changed

+66
-28
lines changed

2 files changed

+66
-28
lines changed

.github/workflows/auto-release-on-merge.yml

Lines changed: 64 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,29 @@ jobs:
3434
run: |
3535
pip install toml
3636
37+
- name: Validate and sanitize user inputs
38+
id: sanitize
39+
run: |
40+
# Sanitize PR title - remove dangerous characters, limit length
41+
SAFE_PR_TITLE=$(printf '%s' '${{ github.event.pull_request.title }}' | \
42+
sed 's/[`$();|&<>]//g' | \
43+
sed 's/[[:cntrl:]]//g' | \
44+
cut -c1-100)
45+
46+
# Validate PR title is not empty after sanitization
47+
if [ -z "$SAFE_PR_TITLE" ]; then
48+
SAFE_PR_TITLE="Untitled PR"
49+
fi
50+
51+
# Log sanitization results
52+
echo "🔒 Input validation results:"
53+
echo "Original PR title: ${{ github.event.pull_request.title }}"
54+
echo "Sanitized PR title: $SAFE_PR_TITLE"
55+
echo ""
56+
57+
# Set outputs
58+
echo "pr_title=$SAFE_PR_TITLE" >> $GITHUB_OUTPUT
59+
3760
- name: Detect changed services and extract versions
3861
id: detect-changes
3962
run: |
@@ -155,13 +178,17 @@ jobs:
155178
156179
echo "✅ Creating tag: $TAG_NAME"
157180
158-
# Create tag with PR information
181+
# Create tag with sanitized PR information
182+
PR_TITLE="${{ steps.sanitize.outputs.pr_title }}"
183+
MERGED_BY="${{ github.event.pull_request.merged_by.login }}"
184+
185+
# Create tag message with sanitized inputs
159186
git tag -a "$TAG_NAME" -m "${service} v${version}
160187
161-
Auto-generated from merged PR #${{ github.event.pull_request.number }}
162-
PR Title: ${{ github.event.pull_request.title }}
163-
Merged by: ${{ github.event.pull_request.merged_by.login }}
164-
Commit: ${{ github.sha }}"
188+
Auto-generated from merged PR #${{ github.event.pull_request.number }}
189+
PR Title: ${PR_TITLE}
190+
Merged by: ${MERGED_BY}
191+
Commit: ${{ github.sha }}"
165192
166193
# Push tag with error handling
167194
if git push origin "$TAG_NAME"; then
@@ -217,14 +244,17 @@ jobs:
217244
*) DISPLAY_NAME="$service" ;;
218245
esac
219246
220-
# Create release notes
247+
# Create release notes with sanitized inputs
248+
PR_TITLE="${{ steps.sanitize.outputs.pr_title }}"
249+
MERGED_BY="${{ github.event.pull_request.merged_by.login }}"
250+
221251
RELEASE_NOTES="## 🚀 $DISPLAY_NAME MCP Server v$version
222252
223253
### 📋 What's Changed
224254
This release was automatically generated from merged PR #${{ github.event.pull_request.number }}.
225255
226-
**PR Title**: ${{ github.event.pull_request.title }}
227-
**Merged by**: @${{ github.event.pull_request.merged_by.login }}
256+
**PR Title**: ${PR_TITLE}
257+
**Merged by**: @${MERGED_BY}
228258
229259
### 📦 Installation
230260
\`\`\`bash
@@ -302,36 +332,42 @@ jobs:
302332
else
303333
echo "✅ Creating umbrella tag: $UMBRELLA_TAG"
304334
305-
# Create umbrella tag
335+
# Create umbrella tag with sanitized inputs
336+
PR_TITLE="${{ steps.sanitize.outputs.pr_title }}"
337+
MERGED_BY="${{ github.event.pull_request.merged_by.login }}"
338+
306339
git tag -a "$UMBRELLA_TAG" -m "HPE GreenLake MCP v${FIRST_SERVICE_VERSION} - All Services Release
307340
308-
Auto-generated from merged PR #${{ github.event.pull_request.number }}
309-
PR Title: ${{ github.event.pull_request.title }}
310-
Merged by: ${{ github.event.pull_request.merged_by.login }}
311-
312-
Services with new tags:
313-
$(for tag in $CREATED_TAGS; do echo "- $tag"; done)
314-
315-
$(if [ -n "$SKIPPED_TAGS" ]; then
316-
echo "Services with existing tags (skipped):"
317-
for tag in $SKIPPED_TAGS; do echo "- $tag"; done
318-
fi)
319-
320-
Commit: ${{ github.sha }}"
341+
Auto-generated from merged PR #${{ github.event.pull_request.number }}
342+
PR Title: ${PR_TITLE}
343+
Merged by: ${MERGED_BY}
344+
345+
Services with new tags:
346+
$(for tag in $CREATED_TAGS; do echo "- $tag"; done)
347+
348+
$(if [ -n "$SKIPPED_TAGS" ]; then
349+
echo "Services with existing tags (skipped):"
350+
for tag in $SKIPPED_TAGS; do echo "- $tag"; done
351+
fi)
352+
353+
Commit: ${{ github.sha }}"
321354
322355
git push origin "$UMBRELLA_TAG"
323356
fi
324357
325358
# Only create release if we have some new tags
326359
if [ -n "$CREATED_TAGS" ]; then
327-
# Create release notes for all services
360+
# Create release notes for all services with sanitized inputs
361+
PR_TITLE="${{ steps.sanitize.outputs.pr_title }}"
362+
MERGED_BY="${{ github.event.pull_request.merged_by.login }}"
363+
328364
ALL_SERVICES_NOTES="## 🚀 HPE GreenLake MCP v${FIRST_SERVICE_VERSION} - All Services Release
329365
330366
### 📋 What's Changed
331367
This is a comprehensive release updating HPE GreenLake MCP servers.
332368
333-
**PR Title**: ${{ github.event.pull_request.title }}
334-
**Merged by**: @${{ github.event.pull_request.merged_by.login }}
369+
**PR Title**: ${PR_TITLE}
370+
**Merged by**: @${MERGED_BY}
335371
**PR Number**: #${{ github.event.pull_request.number }}
336372
337373
### 🏷️ New Service Tags
@@ -443,9 +479,11 @@ jobs:
443479
- name: Create workflow summary
444480
if: always()
445481
run: |
482+
PR_TITLE="${{ steps.sanitize.outputs.pr_title }}"
483+
446484
echo "## 🎉 Auto Release Summary" >> $GITHUB_STEP_SUMMARY
447485
echo "" >> $GITHUB_STEP_SUMMARY
448-
echo "**PR**: #${{ github.event.pull_request.number }} - ${{ github.event.pull_request.title }}" >> $GITHUB_STEP_SUMMARY
486+
echo "**PR**: #${{ github.event.pull_request.number }} - ${PR_TITLE}" >> $GITHUB_STEP_SUMMARY
449487
echo "**Merged by**: @${{ github.event.pull_request.merged_by.login }}" >> $GITHUB_STEP_SUMMARY
450488
echo "**Commit**: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
451489
echo "" >> $GITHUB_STEP_SUMMARY

.github/workflows/ci-public.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
env:
3232
AUTH_TOKEN: ${{ secrets.AUTH_TOKEN || '' }}
3333
ORG: ${{ github.repository_owner }}
34-
TRUSTED_USERS: "lchinglen,vandewillysilva,chamur,alexandrealvino,sunkarar"
34+
TRUSTED_USERS: "lchinglen,vandewillysilva,chamur,alexandrealvino,HemrajChandan,r-nishanth-sai"
3535
TRUSTED_TEAMS: "gl-mcp"
3636
run: |
3737
# Push events are always authorized
@@ -343,7 +343,7 @@ jobs:
343343
echo "::group::Upgrading pip for security"
344344
python -m pip install --upgrade pip
345345
echo "✅ pip upgraded to latest version"
346-
echo "::endgroup::"
346+
echo "::endgroup::"
347347
348348
- name: Secrets detection (detect-secrets)
349349
if: always() && matrix.python-version == env.DEFAULT_PYTHON_VERSION

0 commit comments

Comments
 (0)