Skip to content
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
19 changes: 14 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,7 @@ jobs:
steps:
- checkout
- *load_variables_from_dotenv

#;< CI_GITLEAKS
- *step_setup_remote_docker
#;> CI_GITLEAKS

#;< VORTEX_DEV
#; Vortex does not track 'composer.lock', so resolve dependencies to give
Expand Down Expand Up @@ -261,9 +258,21 @@ jobs:
npx --yes audit-ci@7.1.0 --high --extra-args=--package-lock-only --directory "${dir}" "${config[@]}" || [ "${VORTEX_CI_NPM_AUDIT_IGNORE_FAILURE:-0}" -eq 1 ]
#;> DRUPAL_THEME

#;< CI_GITLEAKS
# The remote Docker engine has no access to the checkout, so the files
# are copied into the container.
# are copied into the container. Semgrep detects PHP by the '.php'
# extension only, so Drupal PHP files with other extensions are passed
# explicitly. Explicit targets skip Semgrep's ignore rules, so test
# directories are excluded here.
- run:
name: Scan PHP code for vulnerabilities with Semgrep
when: always
command: |
mapfile -t files < <(git ls-files '*.module' '*.install' '*.theme' '*.inc' '*.profile' '*.engine' ':(exclude,glob)**/tests/**' ':(exclude,glob)**/test/**')
container="$(docker create --rm -w /src semgrep/semgrep:1.185.0 semgrep scan --config p/php --metrics=off --error --scan-unknown-extensions . "${files[@]}")"
docker cp ./. "${container}:/src"
docker start --attach "${container}" || [ "${VORTEX_CI_SEMGREP_IGNORE_FAILURE:-0}" -eq 1 ]

#;< CI_GITLEAKS
- run:
name: Scan for committed secrets with Gitleaks
when: always
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,24 @@ jobs:
category: npm-audit-theme
#;> DRUPAL_THEME

# Semgrep detects PHP by the '.php' extension only, so Drupal PHP files
# with other extensions are passed explicitly. Explicit targets skip
# Semgrep's ignore rules, so test directories are excluded here.
- name: Scan PHP code for vulnerabilities with Semgrep
if: ${{ !cancelled() }}
run: |
mapfile -t files < <(git ls-files '*.module' '*.install' '*.theme' '*.inc' '*.profile' '*.engine' ':(exclude,glob)**/tests/**' ':(exclude,glob)**/test/**')
docker run --rm --volumes-from "${HOSTNAME}" -w "${PWD}" semgrep/semgrep:1.185.0 semgrep scan --config p/php --metrics=off --error --sarif-output=.logs/audit/semgrep.sarif --scan-unknown-extensions . "${files[@]}"
continue-on-error: ${{ vars.VORTEX_CI_SEMGREP_IGNORE_FAILURE == '1' }}

- name: Upload Semgrep findings to code scanning
if: ${{ !cancelled() && hashFiles('.logs/audit/semgrep.sarif') != '' }}
uses: github/codeql-action/upload-sarif@24c54180a607b1449ed407dd24f251e4e9147c8d # v4
continue-on-error: true
with:
sarif_file: .logs/audit/semgrep.sarif
category: semgrep

#;< CI_GITLEAKS
- name: Scan for committed secrets with Gitleaks
if: ${{ !cancelled() }}
Expand All @@ -210,3 +228,39 @@ jobs:
path: .logs/audit
include-hidden-files: true
if-no-files-found: ignore

# The CodeQL action runs on the runner itself rather than in the CI runner
# container. CodeQL on a private repository requires a GitHub Code Security
# license.
codeql:
runs-on: ubuntu-latest
if: ${{ vars.VORTEX_CI_CODEQL_SKIP != '1' }}

permissions:
# The code scanning upload reads the workflow run in a private repository.
actions: read
contents: read
security-events: write

steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false

- name: Initialize CodeQL
uses: github/codeql-action/init@24c54180a607b1449ed407dd24f251e4e9147c8d # v4
with:
languages: actions,javascript-typescript
build-mode: none
#;< VORTEX_DEV
config: |
paths-ignore:
- .vortex/installer/tests/Fixtures
#;> VORTEX_DEV

- name: Scan code for vulnerabilities with CodeQL
uses: github/codeql-action/analyze@24c54180a607b1449ed407dd24f251e4e9147c8d # v4
# CodeQL reports its findings only to code scanning, and the upload fails
# without a code scanning entitlement and on fork pull requests.
continue-on-error: true
16 changes: 8 additions & 8 deletions .vortex/docs/.utils/serve-router.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@

declare(strict_types=1);

$doc_root = $_SERVER['DOCUMENT_ROOT'];
$doc_root = realpath($_SERVER['DOCUMENT_ROOT']);
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$path = is_string($path) ? rawurldecode($path) : '/';

// Reject traversal outside the build directory before touching the filesystem.
if (str_contains($path, '..')) {
$target = realpath($doc_root . $path);

// Reject a path that resolves outside the build directory.
if ($target !== FALSE && $target !== $doc_root && !str_starts_with($target, $doc_root . DIRECTORY_SEPARATOR)) {
http_response_code(400);

return TRUE;
}

$target = $doc_root . $path;

// Serve an existing file as-is and let the server set the content type.
if (is_file($target)) {
if ($target !== FALSE && is_file($target)) {
return FALSE;
}

$index = rtrim($target, '/') . '/index.html';
$index = $target === FALSE ? FALSE : realpath($target . '/index.html');
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

if (is_file($index)) {
if ($index !== FALSE && str_starts_with($index, $doc_root . DIRECTORY_SEPARATOR) && is_file($index)) {
header('Content-Type: text/html; charset=UTF-8');
readfile($index);

Expand Down
6 changes: 6 additions & 0 deletions .vortex/docs/.utils/variables/extra/ci.variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ VORTEX_CI_COMPOSER_AUDIT_IGNORE_FAILURE=0
# Ignore `npm audit` failures.
VORTEX_CI_NPM_AUDIT_IGNORE_FAILURE=0

# Ignore Semgrep failures.
VORTEX_CI_SEMGREP_IGNORE_FAILURE=0

# Skip the CodeQL scan.
VORTEX_CI_CODEQL_SKIP=0

# Ignore PHPCS failures.
VORTEX_CI_PHPCS_IGNORE_FAILURE=0

Expand Down
2 changes: 2 additions & 0 deletions .vortex/docs/.vale/config/vocabularies/Vortex/accept.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Behat
CircleCI
ClamAV
Codecov
CodeQL
CodeRabbit
Composer
DCLint
Expand All @@ -30,6 +31,7 @@ Prompty
Pygmy
Rector
Renovate
Semgrep
Solr
Storybook
Stylelint
Expand Down
44 changes: 30 additions & 14 deletions .vortex/docs/content/continuous-integration/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ provider defines the workflow in its own file:
| GitHub Actions | The `Security audit` workflow in `.github/workflows/audit.yml` |
| CircleCI | The `audit` workflow in `.circleci/config.yml` |

The workflow runs the same 4 checks on both providers. The checks read only
the codebase and its lock files, so the audit never waits for a build:
The workflow runs the following checks. They read only the codebase and its
lock files, so the audit never waits for a build:

- `composer audit --locked` checks the packages pinned in `composer.lock`
against published security advisories.
Expand All @@ -152,11 +152,19 @@ the codebase and its lock files, so the audit never waits for a build:
`package-lock.json`, with the theme's own `package-audit.jsonc`.
- [Gitleaks](../development/security/secret-scanning.mdx) scans the codebase
for committed secrets.
- [Semgrep](../development/security/code-scanning.mdx) scans the PHP code
for vulnerabilities.
- [CodeQL](../development/security/code-scanning.mdx) scans the GitHub
Actions workflows and the JavaScript code for vulnerabilities. It runs on
GitHub Actions only.

Only the Composer check is always present. The root npm check ships when
your project keeps ESLint, Stylelint or Jest. The theme check ships with a
custom theme. The Gitleaks check ships when you turn on secret scanning at
install time.
On GitHub Actions, CodeQL runs in a separate `codeql` job of the same
workflow. The other checks run in the `audit` job.

The Composer, Semgrep and CodeQL checks are always present. The root npm
check ships when your project keeps ESLint, Stylelint or Jest. The theme
check ships with a custom theme. The Gitleaks check ships when you turn on
secret scanning at install time.

Every check runs even if an earlier check failed, so a single run reports
all the findings. The workflow fails if any check failed, unless that
Expand Down Expand Up @@ -189,13 +197,17 @@ repository's **Security > Code scanning** tab, each under its own category:
| `npm-audit` | `npm audit` advisories for the root `package-lock.json` |
| `npm-audit-theme` | `npm audit` advisories for the custom theme's `package-lock.json` |
| `gitleaks` | Committed secrets |
| `semgrep` | Semgrep vulnerabilities in the PHP code |
| `/language:actions` | CodeQL vulnerabilities in the GitHub Actions workflows |
| `/language:javascript-typescript` | CodeQL vulnerabilities in the JavaScript and TypeScript code |

Code scanning keeps a history of every finding and tracks whether it's open
or fixed. When you dismiss a false positive, the alert stores the reason,
so the repository needs no ignore entry for it.

Gitleaks writes SARIF itself. `composer audit` and `npm audit` have no
SARIF formatter, so each of those checks runs once in JSON format. It pipes
Gitleaks, Semgrep and CodeQL write SARIF themselves. `composer audit` and
`npm audit` have no SARIF formatter, so each of those checks runs once in
JSON format. It pipes
its output through `tee`, which feeds the job log and a report file in
`.logs/audit/` from the same run. The npm checks pass
`--output-format json --report-type full` to `audit-ci`, so `audit-ci`
Expand All @@ -222,17 +234,20 @@ it, and private repositories need a GitHub Code Security license.
Without code scanning, and on pull requests from forks where the workflow
token is read-only, the upload step fails and the workflow carries on. The
checks still report their findings in the job log and still fail the
workflow. Every report is also attached to the run as the
workflow. CodeQL is the exception: its findings appear only in code
scanning. Every other report is also attached to the run as the
`security-findings` artifact.

CircleCI has no code scanning destination. On CircleCI, the same checks run
and fail the `audit` workflow, and their findings appear only in the job
log.
CircleCI has no code scanning destination. On CircleCI, every check except
CodeQL runs and fails the `audit` workflow, and the findings appear only in
the job log.

➡️ See [Dependency audit > Dismissing a
finding](../development/security/dependency-audit.mdx#dismiss-a-finding)
and [Secret scanning > Dismissing a
finding](../development/security/dependency-audit.mdx#dismiss-a-finding),
[Secret scanning > Dismissing a
finding](../development/security/secret-scanning.mdx#dismiss-a-finding)
and [Code vulnerability scanning > Dismissing a
finding](../development/security/code-scanning.mdx#dismiss-a-finding)
for what dismissing a finding does and doesn't change.

## Working tree check
Expand Down Expand Up @@ -847,6 +862,7 @@ The following table lists the variable for each tool:
| [PHPStan](../development/code-quality/phpstan.mdx) | Analyze PHP code statically | `VORTEX_CI_PHPSTAN_IGNORE_FAILURE` |
| [PHPUnit](../development/testing/phpunit.mdx) | Run unit, kernel and functional tests | `VORTEX_CI_PHPUNIT_IGNORE_FAILURE` |
| [Rector](../development/code-quality/rector.mdx) | Check for automated refactoring rules | `VORTEX_CI_RECTOR_IGNORE_FAILURE` |
| [Semgrep](../development/security/code-scanning.mdx) | Scan PHP code for vulnerabilities | `VORTEX_CI_SEMGREP_IGNORE_FAILURE` |
| [SDC Devel](../development/code-quality/sdc-devel.mdx) | Validate Single Directory Components | `VORTEX_CI_SDC_DEVEL_IGNORE_FAILURE` |
| [Twig CS Fixer](../development/code-quality/twig-cs-fixer.mdx) | Lint Twig templates | `VORTEX_CI_TWIG_CS_FIXER_IGNORE_FAILURE` |
| [Working tree check](#working-tree-check) | Check for files left behind by the build | `VORTEX_CI_WORKTREE_CHANGES_IGNORE_FAILURE` |
Expand Down
7 changes: 4 additions & 3 deletions .vortex/docs/content/development/dependency-updates.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ of each:
| **Drupal core** | `drupal/core-recommended`, `drupal/core-composer-scaffold`, `drupal/core-project-message` and `drupal/core-dev` | Minor, patch | Daily before 2 AM UTC | None |
| **Drupal contrib and PHP packages (non-core)** | All Drupal contrib modules and non-Drupal Packagist packages | Minor, patch | Weekly, Sunday before 2 AM UTC | 14 days for Packagist packages |
| **JS packages** | All npm packages (root `package.json` only) | Minor, patch | Weekly, Sunday before 2 AM UTC | 14 days |
| **Container images** | Images in `.docker/` and `docker-compose.yml`, and the images CI starts with `docker run` | Major, minor, patch | Daily before 3 AM UTC | 14 days for Docker Hub images |
| **Container images** | Images in `.docker/` and `docker-compose.yml`, and the images CI starts with `docker run` or `docker create` | Major, minor, patch | Daily before 3 AM UTC | 14 days for Docker Hub images |
| **CI tools** | npm packages that CI runs at a pinned version through `npx` | Major, minor, patch | Daily before 3 AM UTC | 14 days |
| **Renovate version** | The `renovate/renovate` image in `.circleci/update-dependencies.yml`, and the `renovate-version` and `validator_version` inputs in `.github/workflows/` | Major, minor, patch | Weekly, Sunday before 3 AM UTC | 14 days |
| **GitHub Actions** | All actions, and the container images that the jobs in `.github/workflows/` run in, all pinned to digests | Major, minor, patch | Daily before 3 AM UTC | 14 days |
Expand Down Expand Up @@ -440,8 +440,9 @@ Renovate reads only the files that the managers in `enabledManagers` cover:
- `docker-compose` for `docker-compose.yml`
- `github-actions` for the workflows in `.github/workflows/`
- `custom.regex` for 5 custom managers: the `IMAGE` build argument in
`docker-compose.yml`, the `docker run` and `npx --yes` lines in
`.circleci/config.yml` and `.github/workflows/`, the `renovate/renovate`
`docker-compose.yml`, the `docker run`, `docker create` and `npx --yes`
lines in `.circleci/config.yml` and `.github/workflows/`, the
`renovate/renovate`
image in `.circleci/update-dependencies.yml`, and the `renovate-version`
and `validator_version` inputs in `.github/workflows/`

Expand Down
10 changes: 7 additions & 3 deletions .vortex/docs/content/development/security/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ sidebar_position: 1
# Security

This overview is for developers and leads on a project built from
**Vortex**. It shows which check or setting covers each of 3 common risks,
**Vortex**. It shows which check or setting covers each of 4 common risks,
and where it runs:

- [Secret scanning](secret-scanning.mdx) catches an API token committed to
Git.
- The [dependency audit](dependency-audit.mdx) reports a dependency with a
published vulnerability.
- [Code vulnerability scanning](code-scanning.mdx) reports a vulnerability
in the code your team writes, such as a file path built from request
input.
- Shield puts a password prompt in front of a development site on a public
URL. The following section describes it.

Expand Down Expand Up @@ -52,7 +55,8 @@ on Lagoon. On Acquia, the platform's own PHP settings apply.

## Continuous integration

Secret scanning and the dependency audit run in the [security audit
Secret scanning, the dependency audit and code vulnerability scanning run in
the [security audit
workflow](../../continuous-integration/README.mdx#security-audit), separate
from the build pipeline. A failing audit therefore shows up separately from
a failing linter, and you can re-run the audit on its own.
Expand All @@ -61,7 +65,7 @@ The `deploy` job doesn't depend on the audit, so a failing audit doesn't
stop a deployment. To block merges on the audit, add its check to the
repository's branch protection rules as a required status check.

In GitHub Actions, both checks also upload their findings to the
In GitHub Actions, every check also uploads its findings to the
repository's **Security > Code scanning** tab, which keeps an inventory of
the open findings. The GitHub Actions workflow also attaches every report
to the run as the `security-findings` artifact. CircleCI has no code
Expand Down
Loading
Loading