Skip to content

Conversation

@v-atulyadav
Copy link
Collaborator

Required items, please complete

Change(s):

  • See guidance below

Reason for Change(s):

  • See guidance below

Version Updated:

  • Required only for Detections/Analytic Rule templates
  • See guidance below

Testing Completed:

  • See guidance below

Checked that the validations are passing and have addressed any issues that are present:

  • See guidance below

Guidance <- remove section before submitting


Before submitting this PR please ensure that you have read the following sections and filled out the changes, reason for change and testing complete sections:

Thank you for your contribution to the Microsoft Sentinel Github repo.

Details of the code changes in your submitted PR. Providing descriptions for pull requests ensures there is context to changes being made and greatly enhances the code review process. Providing associated Issues that this resolves also easily connects the reason.

Change(s):

  • Updated syntax for XYZ.yaml

Reason for Change(s):

Version updated:

  • Yes
  • Detections/Analytic Rule templates are required to have the version updated

The code should have been tested in a Microsoft Sentinel environment that does not have any custom parsers, functions or tables, so that you validate no incorrect syntax and execution functions properly. If your submission requires a custom parser or function, it must be submitted with the PR.

Testing Completed:

  • Yes/No/Need Help

Note: If updating a detection, you must update the version field.

Before the submission has been made, please look at running the KQL and Yaml Validation Checks locally.
https://github.com/Azure/Azure-Sentinel#run-kql-validation-locally

Checked that the validations are passing and have addressed any issues that are present:

  • Yes/No/Need Help

Note: Let us know if you have tried fixing the validation error and need help.

References:


Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the security of the ASIM testing workflow by implementing several critical security controls to protect against malicious code execution from forked pull requests.

Key changes:

  • Switched from pull_request to pull_request_target trigger with stricter SafeToRun label approval logic
  • Inverted the approval logic to only allow execution on the labeled event, requiring re-approval for any code changes
  • Implemented isolated execution environments for all downloaded Python and PowerShell scripts to prevent import shadowing and code injection attacks

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

echo "Creating isolated execution environment..."
TMPDIR=$(mktemp -d) && trap "rm -rf $TMPDIR" EXIT
echo "Downloading script from master to isolated directory..."
curl -sSf https://raw.githubusercontent.com/Azure/Azure-Sentinel/master/.script/tests/asimParsersTest/ASimFilteringTest.py -o "$TMPDIR/script.py"
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

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

The curl command uses the -f flag (fail silently on HTTP errors), but if the download fails, the script will still attempt to execute the non-existent or partially downloaded script file. This could lead to cryptic error messages or unexpected behavior. Consider adding explicit error checking after the curl command to verify the download succeeded before proceeding with execution.

Suggested change
curl -sSf https://raw.githubusercontent.com/Azure/Azure-Sentinel/master/.script/tests/asimParsersTest/ASimFilteringTest.py -o "$TMPDIR/script.py"
if ! curl -sSf https://raw.githubusercontent.com/Azure/Azure-Sentinel/master/.script/tests/asimParsersTest/ASimFilteringTest.py -o "$TMPDIR/script.py"; then
echo "Error: Failed to download ASimFilteringTest.py from master. Aborting."
exit 1
fi
if [ ! -s "$TMPDIR/script.py" ]; then
echo "Error: Downloaded script file is missing or empty: $TMPDIR/script.py"
exit 1
fi

Copilot uses AI. Check for mistakes.
Comment on lines +341 to +342
Invoke-WebRequest https://raw.githubusercontent.com/Azure/Azure-Sentinel/master/.script/tests/asimParsersTest/runAsimTesters.ps1 -OutFile "$tmpDir/script.ps1"
Invoke-WebRequest https://raw.githubusercontent.com/Azure/Azure-Sentinel/master/.script/tests/asimParsersTest/convertYamlToObject.ps1 -OutFile "$tmpDir/helper.ps1"
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

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

The PowerShell script downloads two scripts to an isolated directory but doesn't verify that the downloads succeeded before attempting to execute them. If either Invoke-WebRequest fails, the script execution could fail with unclear error messages. Consider adding error checking or using -ErrorAction Stop to ensure download failures are caught properly.

Suggested change
Invoke-WebRequest https://raw.githubusercontent.com/Azure/Azure-Sentinel/master/.script/tests/asimParsersTest/runAsimTesters.ps1 -OutFile "$tmpDir/script.ps1"
Invoke-WebRequest https://raw.githubusercontent.com/Azure/Azure-Sentinel/master/.script/tests/asimParsersTest/convertYamlToObject.ps1 -OutFile "$tmpDir/helper.ps1"
Invoke-WebRequest https://raw.githubusercontent.com/Azure/Azure-Sentinel/master/.script/tests/asimParsersTest/runAsimTesters.ps1 -OutFile "$tmpDir/script.ps1" -ErrorAction Stop
Invoke-WebRequest https://raw.githubusercontent.com/Azure/Azure-Sentinel/master/.script/tests/asimParsersTest/convertYamlToObject.ps1 -OutFile "$tmpDir/helper.ps1" -ErrorAction Stop
if (-not (Test-Path "$tmpDir/script.ps1") -or -not (Test-Path "$tmpDir/helper.ps1")) {
throw "Failed to download required ASIM test scripts to isolated directory."
}

Copilot uses AI. Check for mistakes.
# Check if this workflow was triggered by new commits (synchronize event)
# SECURITY: Only allow 'labeled' event to pass when SafeToRun exists
# Block ALL other events (synchronize, edited, reopened) to prevent bypass
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

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

The security comment states "Block ALL other events (synchronize, edited, reopened)" but the workflow trigger on line 6 still includes these events in the types list. This creates a mismatch between the documented security intent and the actual trigger configuration. If these events should truly be blocked, they should be removed from the trigger types list, or the comment should be clarified to indicate they trigger the workflow but require re-approval.

Suggested change
# Block ALL other events (synchronize, edited, reopened) to prevent bypass
# Other events (synchronize, edited, reopened) still trigger this workflow,
# but are blocked from approval and require re-applying the 'SafeToRun' label

Copilot uses AI. Check for mistakes.
Invoke-WebRequest https://raw.githubusercontent.com/Azure/Azure-Sentinel/master/.script/tests/asimParsersTest/runAsimTesters.ps1 -OutFile "$tmpDir/script.ps1"
Invoke-WebRequest https://raw.githubusercontent.com/Azure/Azure-Sentinel/master/.script/tests/asimParsersTest/convertYamlToObject.ps1 -OutFile "$tmpDir/helper.ps1"
Write-Host "Executing script from isolated environment..."
Push-Location $env:GITHUB_WORKSPACE
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

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

The PowerShell script execution logic has a critical issue. The script changes the working directory to GITHUB_WORKSPACE using Push-Location, but the scripts being executed (runAsimTesters.ps1 and convertYamlToObject.ps1) are downloaded to a temporary directory. If these scripts need to reference each other or other files using relative paths, they won't be able to find them because they're not in the same directory where the working directory is set. The helper script (convertYamlToObject.ps1) should be in the same directory as the main script for it to be discoverable, but the working directory is changed away from where they're stored.

Suggested change
Push-Location $env:GITHUB_WORKSPACE
Push-Location $tmpDir

Copilot uses AI. Check for mistakes.
echo "Creating isolated execution environment..."
TMPDIR=$(mktemp -d) && trap "rm -rf $TMPDIR" EXIT
echo "Downloading script from master to isolated directory..."
curl -sSf https://raw.githubusercontent.com/Azure/Azure-Sentinel/master/.script/tests/asimParsersTest/VerifyASimParserTemplate.py -o "$TMPDIR/script.py"
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

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

The curl command uses the -f flag (fail silently on HTTP errors), but if the download fails, the script will still attempt to execute the non-existent or partially downloaded script file. This could lead to cryptic error messages or unexpected behavior. Consider adding explicit error checking after the curl command to verify the download succeeded before proceeding with execution.

Suggested change
curl -sSf https://raw.githubusercontent.com/Azure/Azure-Sentinel/master/.script/tests/asimParsersTest/VerifyASimParserTemplate.py -o "$TMPDIR/script.py"
curl -sSf https://raw.githubusercontent.com/Azure/Azure-Sentinel/master/.script/tests/asimParsersTest/VerifyASimParserTemplate.py -o "$TMPDIR/script.py"
if [ $? -ne 0 ] || [ ! -s "$TMPDIR/script.py" ]; then
echo "Error: Failed to download VerifyASimParserTemplate.py or file is empty." >&2
exit 1
fi

Copilot uses AI. Check for mistakes.
echo "Creating isolated execution environment..."
TMPDIR=$(mktemp -d) && trap "rm -rf $TMPDIR" EXIT
echo "Downloading script from master to isolated directory..."
curl -sSf https://raw.githubusercontent.com/Azure/Azure-Sentinel/master/.script/tests/asimParsersTest/ingestASimSampleData.py -o "$TMPDIR/script.py"
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

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

The curl command uses the -f flag (fail silently on HTTP errors), but if the download fails, the script will still attempt to execute the non-existent or partially downloaded script file. This could lead to cryptic error messages or unexpected behavior. Consider adding explicit error checking after the curl command to verify the download succeeded before proceeding with execution.

Suggested change
curl -sSf https://raw.githubusercontent.com/Azure/Azure-Sentinel/master/.script/tests/asimParsersTest/ingestASimSampleData.py -o "$TMPDIR/script.py"
if ! curl -sSf https://raw.githubusercontent.com/Azure/Azure-Sentinel/master/.script/tests/asimParsersTest/ingestASimSampleData.py -o "$TMPDIR/script.py"; then
echo "Error: Failed to download ingestASimSampleData.py from master branch."
exit 1
fi
if [ ! -s "$TMPDIR/script.py" ]; then
echo "Error: Downloaded script is missing or empty: $TMPDIR/script.py"
exit 1
fi

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants