Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create bito-actions.sh #31

Merged
merged 5 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions bito-action-script/bito-actions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash

# Function to read property values from the file
read_property() {
local property_key=$1
local property_file=$2
local property_value=$(grep -w "${property_key}" "${property_file}" | cut -d'=' -f2-)
echo "${property_value//\"}"
}

# Initialize variables with default empty values
agent_instance_url=""
agent_instance_secret=""
git_url=""

# Check if the first argument is a file
if [ -f "$1" ]; then
PROPERTY_FILE=$1
shift

# Read initial values from the property file
agent_instance_url=$(read_property "agent_instance_url" "${PROPERTY_FILE}")
agent_instance_secret=$(read_property "agent_instance_secret" "${PROPERTY_FILE}")
git_url=$(read_property "git_url" "${PROPERTY_FILE}")
fi

# Override with command line arguments if provided
for arg in "$@"
do
case $arg in
agent_instance_url=*)
agent_instance_url="${arg#*=}"
agent_instance_url="${agent_instance_url//\"}"
;;
agent_instance_secret=*)
agent_instance_secret="${arg#*=}"
agent_instance_secret="${agent_instance_secret//\"}"
;;
git_url=*)
git_url="${arg#*=}"
git_url="${git_url//\"}"
;;
*)
echo "Unknown argument: $arg"
;;
esac
done

# Check if any of the required properties are empty
if [ -z "$agent_instance_url" ]; then
echo "Error: agent_instance_url is empty"
exit 1
fi

if [ -z "$agent_instance_secret" ]; then
echo "Error: agent_instance_secret is empty"
exit 1
fi

if [ -z "$git_url" ]; then
echo "Error: git_url is empty"
exit 1
fi

# Print properties
echo "Agent Instance URL: $agent_instance_url"
echo "Git URL: $git_url"

# Execute the curl command
eval "curl --location '$agent_instance_url' \
--header 'X-Bito-Action-Token: $agent_instance_secret' \
--header 'Content-Type: application/json' \
--data '{
\"git_url\": \"$git_url\",
\"command\": \"review\",
\"arguments\": {}
}'"
Comment on lines +70 to +77
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bito Code Review Agent Run #d5dade - 08/08/2024, 05:06 pm

🔴 High importance
Issue: The use of 'eval' with user-supplied data can lead to command injection vulnerabilities. This is a critical security risk.
Fix: Avoid using 'eval' and construct the curl command in a safer manner.
Code suggestion
 @@ -69,9 +69,9 @@
 -eval "curl --location '$agent_instance_url' \\
 ---header 'X-Bito-Action-Token: $agent_instance_secret' \\
 ---header 'Content-Type: application/json' \\
 ---data '{
 -    \"git_url\": \"$git_url\",
 -    \"command\": \"review\",
 -    \"arguments\": {}'"
 +curl --location "$agent_instance_url" \
 +--header "X-Bito-Action-Token: $agent_instance_secret" \
 +--header "Content-Type: application/json" \
 +--data '{
 +    "git_url": "'"$git_url"'",
 +    "command": "review",
 +    "arguments": {}'"

Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

3 changes: 3 additions & 0 deletions bito-action-script/bito_action.properties.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
agent_instance_url=
agent_instance_secret=
git_url=