Skip to content

Commit 0d5afc0

Browse files
fix: security fixes for .claude/skills/release/skill.sh
Agent-Logs-Url: https://github.com/optimizely/optimizely-flutter-sdk/sessions/13b89788-5c29-4b2f-addc-f2528768d844 Co-authored-by: muzahidul-opti <129880873+muzahidul-opti@users.noreply.github.com>
1 parent 00210cc commit 0d5afc0

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

.claude/skills/release/skill.sh

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
22
set -euo pipefail
3+
set +H # Disable history expansion to prevent '!' in content from being expanded
34

45
# Optimizely Flutter SDK - Release (Step 2)
56
# Publishes to pub.dev and creates GitHub release
@@ -28,22 +29,28 @@ git diff-index --quiet HEAD -- || error "Working tree has uncommitted changes"
2829
PUBSPEC_VERSION=$(grep '^version:' pubspec.yaml | awk '{print $2}')
2930
[[ "$PUBSPEC_VERSION" != "$VERSION" ]] && error "Version mismatch! pubspec.yaml: $PUBSPEC_VERSION, requested: $VERSION"
3031

31-
# Verify authentication
32+
# Verify authentication (note: gh auth status only checks authentication, not that the
33+
# token has the required 'repo' scope needed to create releases)
3234
gh auth status &>/dev/null || error "GitHub CLI not authenticated. Run: gh auth login"
3335

3436
success "Pre-flight checks passed"
3537

3638
# Create temporary file for dry-run output (prevents symlink attacks)
3739
DRY_RUN_LOG=$(mktemp)
38-
trap "rm -f '$DRY_RUN_LOG'" EXIT
40+
trap "rm -f \"${DRY_RUN_LOG}\"" EXIT
3941

4042
# Dry run
4143
info "Running pub publish dry-run..."
42-
if ! flutter packages pub publish --dry-run 2>&1 | tee "$DRY_RUN_LOG"; then
44+
flutter packages pub publish --dry-run 2>&1 | tee "$DRY_RUN_LOG"
45+
FLUTTER_EXIT="${PIPESTATUS[0]}"
46+
if [[ "$FLUTTER_EXIT" != "0" ]]; then
4347
echo ""
44-
read -p "Dry-run found warnings. Continue? (y/N) " -n 1 -r
48+
if [[ ! -t 0 ]]; then
49+
error "Dry-run found warnings. Cannot prompt in non-interactive mode. Fix warnings or run interactively."
50+
fi
51+
read -p "Dry-run found warnings. Continue? (y/N) " -r -n 1
4552
echo
46-
[[ ! $REPLY =~ ^[Yy]$ ]] && error "Aborted by user"
53+
[[ ! "$REPLY" =~ ^[Yy]$ ]] && error "Aborted by user"
4754
fi
4855

4956
# Publish
@@ -52,10 +59,13 @@ flutter packages pub publish || error "Publishing failed"
5259
success "Published to pub.dev!"
5360

5461
# Extract CHANGELOG
55-
# Escape VERSION for use in sed regex (prevent regex metacharacter interpretation)
62+
# Escape VERSION for use in sed regex (prevent regex metacharacter interpretation).
63+
# VERSION is already validated against ^[0-9]+\.[0-9]+\.[0-9]+(-[a-z0-9]+)?$ above,
64+
# so it cannot contain '|' (the alternate sed delimiter used below); escaping here
65+
# is an additional safety measure for other metacharacters.
5666
ESCAPED_VERSION=$(printf '%s\n' "$VERSION" | sed 's/[.[\*^$()+?{|]/\\&/g')
57-
CHANGELOG_CONTENT=$(sed -n "/^## ${ESCAPED_VERSION}\$/,/^## [0-9]/p" CHANGELOG.md | sed '1d;$d')
58-
[[ -z "$CHANGELOG_CONTENT" ]] && CHANGELOG_CONTENT="Release $VERSION\n\nSee CHANGELOG.md for details."
67+
CHANGELOG_CONTENT=$(sed -n "\|^## ${ESCAPED_VERSION}\$|,\|^## [0-9]|p" CHANGELOG.md | sed '1d;$d')
68+
[[ -z "$CHANGELOG_CONTENT" ]] && CHANGELOG_CONTENT=$(printf 'Release %s\n\nSee CHANGELOG.md for details.' "$VERSION")
5969

6070
RELEASE_NOTES="## $VERSION
6171

0 commit comments

Comments
 (0)