Files
pezkuwi-wallet-android/.github/workflows/security.yml
T

186 lines
6.8 KiB
YAML

name: Security
on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: '0 6 * * 1'
permissions:
contents: read
security-events: write
env:
ACALA_PROD_AUTH_TOKEN: ${{ secrets.ACALA_PROD_AUTH_TOKEN }}
ACALA_TEST_AUTH_TOKEN: ${{ secrets.ACALA_TEST_AUTH_TOKEN }}
MOONBEAM_PROD_AUTH_TOKEN: ${{ secrets.MOONBEAM_PROD_AUTH_TOKEN }}
MOONBEAM_TEST_AUTH_TOKEN: ${{ secrets.MOONBEAM_TEST_AUTH_TOKEN }}
MOONPAY_PRODUCTION_SECRET: ${{ secrets.MOONPAY_PRODUCTION_SECRET }}
MOONPAY_TEST_SECRET: ${{ secrets.MOONPAY_TEST_SECRET }}
MERCURYO_PRODUCTION_SECRET: ${{ secrets.MERCURYO_PRODUCTION_SECRET }}
MERCURYO_TEST_SECRET: ${{ secrets.MERCURYO_TEST_SECRET }}
EHTERSCAN_API_KEY_MOONBEAM: ${{ secrets.EHTERSCAN_API_KEY_MOONBEAM }}
EHTERSCAN_API_KEY_MOONRIVER: ${{ secrets.EHTERSCAN_API_KEY_MOONRIVER }}
EHTERSCAN_API_KEY_ETHEREUM: ${{ secrets.EHTERSCAN_API_KEY_ETHEREUM }}
INFURA_API_KEY: ${{ secrets.INFURA_API_KEY }}
DWELLIR_API_KEY: ${{ secrets.DWELLIR_API_KEY }}
TRONGRID_API_KEY: ${{ secrets.TRONGRID_API_KEY }}
WALLET_CONNECT_PROJECT_ID: ${{ secrets.WALLET_CONNECT_PROJECT_ID }}
DEBUG_GOOGLE_OAUTH_ID: ${{ secrets.DEBUG_GOOGLE_OAUTH_ID }}
RELEASE_GOOGLE_OAUTH_ID: ${{ secrets.RELEASE_GOOGLE_OAUTH_ID }}
jobs:
codeql:
# Advanced setup, because default setup analyses Java without a build and leaves out every
# Kotlin file, which is nearly all of this app.
name: CodeQL (${{ matrix.language }})
runs-on: ubuntu-latest
timeout-minutes: 120
strategy:
fail-fast: false
matrix:
include:
- language: actions
build-mode: none
- language: javascript-typescript
build-mode: none
- language: rust
build-mode: none
- language: java-kotlin
build-mode: manual
steps:
- name: Free disk space
if: matrix.language == 'java-kotlin'
run: |
# The CodeQL bundle in the tool cache is kept: the init step below uses it.
sudo rm -rf /usr/share/dotnet /usr/share/swift /opt/ghc /usr/local/.ghcup \
/usr/local/share/boost /usr/local/share/powershell \
/usr/local/lib/node_modules /usr/local/julia* /opt/microsoft
sudo docker image prune -af > /dev/null 2>&1 || true
df -h /
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
if: matrix.language == 'java-kotlin'
uses: ./.github/workflows/install/
- name: Set up DEV Google Services
if: matrix.language == 'java-kotlin'
uses: davidSchuppa/base64Secret-toFile-action@v3
with:
secret: ${{ secrets.CI_DEVELOP_GOOGLE_SERVICES }}
filename: google-services.json
destination-path: ./app/
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
- name: Build for CodeQL
if: matrix.build-mode == 'manual'
# No Gradle or Kotlin daemon is left running: the analysis after the build needs that memory, and
# with them alive the runner ran out of it during query evaluation.
run: |
./gradlew assembleDebug -x test -x lint --no-daemon -Pkotlin.compiler.execution.strategy=in-process
free -m
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4
with:
category: /language:${{ matrix.language }}
dependency-review:
name: Dependency Review
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Dependency Review
uses: actions/dependency-review-action@v4
with:
fail-on-severity: critical
deny-licenses: GPL-3.0, AGPL-3.0
# TruffleHog (AGPL-3.0) is run unmodified as a CI scanner; it is not
# linked into or shipped with anything, so the licence's obligations
# do not reach this repository. Only this package is exempt.
allow-dependencies-licenses: pkg:githubactions/trufflesecurity/trufflehog
secret-scan:
name: Secret Scan
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
# Push and pull_request scan only the commits they bring: the action picks
# the range from the event. `base: main` made a push to main rescan the
# whole history, where Nova's own Infura keys are still live, so this job
# was red on every push and a new leak would have looked like the old red.
- name: TruffleHog Secret Scan (new commits)
if: github.event_name != 'schedule'
uses: trufflesecurity/trufflehog@e76dff8a7e57d6df0c60ad8cbf5d5cba505a8fc9 # v3.99.2
with:
path: ./
version: 3.99.2
extra_args: --only-verified
# The weekly run checks what is in the tree today, not the history.
- name: TruffleHog Secret Scan (current tree)
if: github.event_name == 'schedule'
run: |
mkdir -p "$RUNNER_TEMP/tree"
git archive HEAD | tar -x -C "$RUNNER_TEMP/tree"
docker run --rm -v "$RUNNER_TEMP/tree:/tree" ghcr.io/trufflesecurity/trufflehog:3.99.2 \
filesystem /tree --fail --no-update --github-actions --only-verified
hardcoded-secrets:
name: Hardcoded Secret Detection
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Scan for hardcoded secrets
run: |
FOUND=0
echo "Checking for seed phrases / mnemonics..."
if grep -rn --include="*.kt" --include="*.java" --include="*.xml" -iE "(mnemonic|seed_phrase)\s*=\s*\"[a-z]+" . | grep -v /build/ | grep -v /test/ | grep -v /androidTest/ | grep -v "R.string" | grep -v "getString"; then
echo "::error::Possible seed phrase found in source"
FOUND=1
fi
echo "Checking for private keys..."
if grep -rn --include="*.kt" --include="*.java" -E "(private_key|privateKey|secret)\s*=\s*\"0x[a-fA-F0-9]{64}\"" . | grep -v /build/ | grep -v /test/ | grep -v /androidTest/; then
echo "::error::Possible private key found in source"
FOUND=1
fi
echo "Checking for API keys in source..."
if grep -rn --include="*.kt" --include="*.java" -iE "(api_key|apikey|secret_key|password)\s*=\s*\"[^\"]{16,}" . | grep -v /build/ | grep -v /test/ | grep -v /androidTest/ | grep -v BuildConfig | grep -v "process"; then
echo "::error::Possible API key or password found in source"
FOUND=1
fi
if [ "$FOUND" -eq 0 ]; then
echo "No hardcoded secrets found."
else
exit 1
fi