forked from OWASP-Benchmark/BenchmarkJava
-
Notifications
You must be signed in to change notification settings - Fork 365
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
Demo branch 1687674691 #6
Open
ammarfadeel
wants to merge
3
commits into
ShiftLeftSecurity:master
Choose a base branch
from
ammarfadeel:demo-branch-1687674691
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
|
||
--- | ||
# This workflow integrates ShiftLeft NG SAST with GitHub | ||
# Visit https://docs.shiftleft.io for help | ||
name: ShiftLeft | ||
|
||
on: | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
NextGen-Static-Analysis: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
# We are building this application with Java 11 | ||
- name: Setup Java JDK | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: zulu | ||
java-version: 11.0.x | ||
- name: Package with maven | ||
run: mvn compile package | ||
- name: Download ShiftLeft CLI | ||
run: | | ||
curl https://cdn.shiftleft.io/download/sl > ${GITHUB_WORKSPACE}/sl && chmod a+rx ${GITHUB_WORKSPACE}/sl | ||
# ShiftLeft requires Java 1.8. Post the package step override the version | ||
- name: Setup Java JDK | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: zulu | ||
java-version: 8 | ||
- name: Extract branch name | ||
shell: bash | ||
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" | ||
id: extract_branch | ||
- name: NextGen Static Analysis | ||
run: ${GITHUB_WORKSPACE}/sl analyze --strict --wait --analysis-timeout=1h --app Benchmark --tag branch=${{ github.head_ref || steps.extract_branch.outputs.branch }} --java --cpg target/benchmark.war | ||
env: | ||
SHIFTLEFT_ACCESS_TOKEN: ${{ secrets.SHIFTLEFT_ACCESS_TOKEN }} | ||
SHIFTLEFT_API_HOST: www.shiftleft.io | ||
SHIFTLEFT_GRPC_TELEMETRY_HOST: telemetry.shiftleft.io:443 | ||
SHIFTLEFT_GRPC_API_HOST: api.shiftleft.io:443 | ||
OWASP-Benchmark-Score: | ||
runs-on: ubuntu-20.04 | ||
needs: NextGen-Static-Analysis | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup Java JDK | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: zulu | ||
java-version: 11.0.x | ||
- name: Export NG SAST Findings | ||
run: | | ||
cd $HOME | ||
git clone --depth 1 --branch v0.0.4 https://github.com/ShiftLeftSecurity/field-integrations | ||
cd field-integrations/shiftleft-utils || exit 1 | ||
mkdir -p ${GITHUB_WORKSPACE}/ngsast_results | ||
pip3 install -r requirements.txt | ||
python3 export.py --app Benchmark -f sl -o ${GITHUB_WORKSPACE}/ngsast_results/Benchmark.sl | ||
env: | ||
SHIFTLEFT_ACCESS_TOKEN: ${{ secrets.SHIFTLEFT_ACCESS_TOKEN }} | ||
SHIFTLEFT_API_HOST: www.shiftleft.io | ||
SHIFTLEFT_GRPC_TELEMETRY_HOST: telemetry.shiftleft.io:443 | ||
SHIFTLEFT_GRPC_API_HOST: api.shiftleft.io:443 | ||
- name: Package with maven | ||
run: mvn compile package | ||
- name: Calculate OWASP Benchmark Score | ||
run: | | ||
cd ${GITHUB_WORKSPACE} | ||
mvn validate -Pbenchmarkscore -Dexec.args="expectedresults-1.2.csv ngsast_results ShiftLeft anonymous" | ||
if [ -e "scorecard/Benchmark_Scorecard_for_ShiftLeft.html" ]; then | ||
echo "*** Thank you for Benchmarking ShiftLeft NextGen Static Analysis ***" | ||
echo "You can find the results for ShiftLeft under workflow artifacts called scorecard" | ||
else | ||
echo "Benchmark results were not produced correctly. Check if you have Java 1.8 installed" | ||
fi | ||
- uses: actions/upload-artifact@v3 | ||
with: | ||
name: Benchmark_v1.2_Scorecard_for_ShiftLeft | ||
path: scorecard | ||
|
||
- name: Generate Results Checksum | ||
run: | | ||
OWASP_BENCHMARK_CHECKSUM=$(tail -n +2 scorecard/Benchmark_v1.2_Scorecard_for_ShiftLeft.csv | | ||
sort | | ||
tr -d '[:space:]' | | ||
tr '[:upper:]' '[:lower:]' | | ||
shasum | | ||
tr -d " -") | ||
echo "OWASP_BENCHMARK_CHECKSUM=$OWASP_BENCHMARK_CHECKSUM" >> $GITHUB_ENV | ||
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 14 | ||
- run: npm install jwt-decode node-fetch@2 | ||
if: github.event_name == 'pull_request' | ||
|
||
- name: Notify Benchmark Results | ||
uses: actions/github-script@v4 | ||
if: github.event_name == 'pull_request' | ||
env: | ||
OWASP_BENCHMARK_CHECKSUM: ${{ env.OWASP_BENCHMARK_CHECKSUM }} | ||
SHIFTLEFT_USER_ID_V2: 791ca050-0ac7-42b1-8e1f-e68adb4cbb34 | ||
SHIFTLEFT_ACCESS_TOKEN: ${{ secrets.SHIFTLEFT_ACCESS_TOKEN }} | ||
SHIFTLEFT_API_HOST: www.shiftleft.io | ||
SHIFTLEFT_GRPC_TELEMETRY_HOST: telemetry.shiftleft.io:443 | ||
SHIFTLEFT_GRPC_API_HOST: api.shiftleft.io:443 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
// Leave a comment on the PR | ||
const { issue: { number: issue_number }, repo: { owner, repo } } = context; | ||
const run = await github.actions.getWorkflowRun({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
run_id: context.runId | ||
}); | ||
const loc = run.data.html_url ? '[GitHub Action](' + run.data.html_url + ')' : 'GitHub Action'; | ||
const body = '👋 ' + '@' + context.actor + ' OWASP Benchmark scorecard is available for download in the Artifacts Section of ' + loc; | ||
github.issues.createComment({ issue_number, owner, repo, body }); | ||
|
||
// Report the results | ||
const jwt_decode = require('jwt-decode'); | ||
const fetch = require("node-fetch"); | ||
const { | ||
SHIFTLEFT_API_HOST, | ||
SHIFTLEFT_ACCESS_TOKEN, | ||
SHIFTLEFT_USER_ID_V2, | ||
OWASP_BENCHMARK_CHECKSUM, | ||
} = process.env; | ||
const decoded = jwt_decode(SHIFTLEFT_ACCESS_TOKEN); | ||
const orgID = decoded.orgID; | ||
const apiHost = SHIFTLEFT_API_HOST || 'app.shiftleft.io'; | ||
fetch(`https://${apiHost}/api/v4/private/orgs/${orgID}/bi_proxy/owasp_benchmark_complete`, { | ||
headers: { | ||
"Content-Type": "application/json; charset=utf-8", | ||
"Authorization": `Bearer ${SHIFTLEFT_ACCESS_TOKEN}`, | ||
}, | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
artifact_url: run.data.html_url || '', | ||
result_sha1: OWASP_BENCHMARK_CHECKSUM, | ||
user_id_v2: SHIFTLEFT_USER_ID_V2, | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
version: 2 | ||
build_rules: | ||
- id: Allow no critical findings | ||
severities: | ||
- critical | ||
- id: Allow one OSS or container finding | ||
finding_types: | ||
- oss_vuln | ||
- container | ||
threshold: 1 | ||
- id: Allow no reachable OSS vulnerability | ||
finding_types: | ||
- oss_vuln | ||
options: | ||
reachable: true |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential Improvements and Debugging: