Skip to content

Commit 9e3fecf

Browse files
authored
Merge pull request #171 from step-security/fix/vulnerability1
Fix/vulnerability1
2 parents dd830cd + f756cdc commit 9e3fecf

4 files changed

Lines changed: 44 additions & 17 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM alpine:3.22.2@sha256:4b7ce07002c69e8f3d704a9c5d6fd3053be500b7f1c69fc0d80990c2ad8dd412
1+
FROM alpine:3.23@sha256:25109184c71bdad752c8312a8623239686a9a2071e8825f20acb8f2198c3f659
22
RUN apk add --no-cache curl docker-cli
33
COPY start-mongodb.sh /start-mongodb.sh
44
RUN chmod +x /start-mongodb.sh

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11

2+
# MongoDB Github Action
3+
[![StepSecurity Maintained Action](https://raw.githubusercontent.com/step-security/maintained-actions-assets/main/assets/maintained-action-banner.png)](https://docs.stepsecurity.io/actions/stepsecurity-maintained-actions)
4+
25
## Introduction
36
This GitHub Action starts a MongoDB server or MongoDB replica set. By default, the MongoDB server is available on the default port `27017`. You can configure a custom port using the `mongodb-port` input. The examples show how to use a custom port.
47

action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,5 @@ runs:
5858
- ${{ inputs.mongodb-username }}
5959
- ${{ inputs.mongodb-password }}
6060
- ${{ inputs.mongodb-container-name }}
61+
env:
62+
REPO_PRIVATE: ${{ github.event.repository.private }}

start-mongodb.sh

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,46 @@ MONGODB_PASSWORD=$7
1111
MONGODB_CONTAINER_NAME=$8
1212

1313
# validate subscription status
14-
API_URL="https://agent.api.stepsecurity.io/v1/github/$GITHUB_REPOSITORY/actions/subscription"
15-
16-
# Set a timeout for the curl command (3 seconds)
17-
RESPONSE=$(curl --max-time 3 -s -w "%{http_code}" "$API_URL" -o /dev/null) || true
18-
CURL_EXIT_CODE=$?
19-
20-
# Decide based on curl exit code and HTTP status
21-
if [ $CURL_EXIT_CODE -ne 0 ]; then
22-
echo "Timeout or API not reachable. Continuing to next step."
23-
elif [ "$RESPONSE" = "200" ]; then
24-
:
25-
elif [ "$RESPONSE" = "403" ]; then
26-
echo "Subscription is not valid. Reach out to support@stepsecurity.io"
27-
exit 1
28-
else
29-
echo "Timeout or API not reachable. Continuing to next step."
14+
UPSTREAM="supercharge/mongodb-github-action"
15+
ACTION_REPO="${GITHUB_ACTION_REPOSITORY:-}"
16+
DOCS_URL="https://docs.stepsecurity.io/actions/stepsecurity-maintained-actions"
17+
18+
echo ""
19+
echo -e "\033[1;36mStepSecurity Maintained Action\033[0m"
20+
echo "Secure drop-in replacement for $UPSTREAM"
21+
if [ "$REPO_PRIVATE" = "false" ]; then
22+
echo -e "\033[32m✓ Free for public repositories\033[0m"
23+
fi
24+
echo -e "\033[36mLearn more:\033[0m $DOCS_URL"
25+
echo ""
26+
27+
if [ "$REPO_PRIVATE" = "true" ]; then
28+
SERVER_URL="${GITHUB_SERVER_URL:-https://github.com}"
29+
30+
if [ "$SERVER_URL" != "https://github.com" ]; then
31+
BODY=$(printf '{"action":"%s","ghes_server":"%s"}' "$ACTION_REPO" "$SERVER_URL")
32+
else
33+
BODY=$(printf '{"action":"%s"}' "$ACTION_REPO")
34+
fi
35+
36+
API_URL="https://agent.api.stepsecurity.io/v1/github/$GITHUB_REPOSITORY/actions/maintained-actions-subscription"
37+
38+
RESPONSE=$(curl --max-time 3 -s -w "%{http_code}" \
39+
-X POST \
40+
-H "Content-Type: application/json" \
41+
-d "$BODY" \
42+
"$API_URL" -o /dev/null) && CURL_EXIT_CODE=0 || CURL_EXIT_CODE=$?
43+
44+
if [ $CURL_EXIT_CODE -ne 0 ]; then
45+
echo "Timeout or API not reachable. Continuing to next step."
46+
elif [ "$RESPONSE" = "403" ]; then
47+
echo -e "\033[1;31mThis action requires a StepSecurity subscription for private repositories.\033[0m"
48+
echo -e "\033[31mLearn how to enable a subscription: $DOCS_URL\033[0m"
49+
exit 1
50+
fi
3051
fi
3152

53+
3254
# `mongosh` is used starting from MongoDB 5.x
3355
MONGODB_CLIENT="mongosh --quiet"
3456

0 commit comments

Comments
 (0)