Skip to content
Open
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
42 changes: 42 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: 2

updates:
- package-ecosystem: composer
directory: "/"
schedule:
interval: weekly
day: monday
time: "06:00"
timezone: Etc/UTC
open-pull-requests-limit: 10
labels:
- dependencies
groups:
php-static-analysis:
patterns:
- "phpstan/*"
- "rector/*"
php-testing:
patterns:
- "phpunit/*"
- "guzzlehttp/*"

- package-ecosystem: github-actions
directory: "/"
schedule:
interval: weekly
day: monday
time: "06:00"
timezone: Etc/UTC
open-pull-requests-limit: 5
labels:
- dependencies
- github-actions

- package-ecosystem: docker
directory: "/docker/php"
schedule:
interval: monthly
labels:
- dependencies
- docker
44 changes: 44 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: 'CodeQL'

on:
push:
branches: ['9.x']
pull_request:
branches: ['9.x']
schedule:
# Run weekly to catch newly published advisories.
- cron: '17 6 * * 1'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
analyze:
name: 'Analyze (${{ matrix.language }})'
runs-on: 'ubuntu-24.04'
timeout-minutes: 30
permissions:
contents: read
security-events: write
actions: read
strategy:
fail-fast: false
matrix:
language: ['actions']
# PHP support in CodeQL is in beta as of 2026; revisit and add 'php'
# to the matrix once it leaves beta.
steps:
- name: 'Checkout'
uses: 'actions/checkout@v4'

- name: 'Initialize CodeQL'
uses: 'github/codeql-action/init@v3'
with:
languages: ${{ matrix.language }}
queries: 'security-and-quality'

- name: 'Perform CodeQL Analysis'
uses: 'github/codeql-action/analyze@v3'
with:
category: '/language:${{ matrix.language }}'
27 changes: 27 additions & 0 deletions .github/workflows/continuous-integration.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
name: 'Continuous integration'
on: ['push', 'pull_request']

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
audit:
runs-on: 'ubuntu-24.04'
name: 'Composer audit'
Comment on lines +9 to +11

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== workflow excerpt =="
if [ -f .github/workflows/continuous-integration.yaml ]; then
  nl -ba .github/workflows/continuous-integration.yaml | sed -n '1,140p'
else
  echo "missing .github/workflows/continuous-integration.yaml"
fi

echo
echo "== all local workflow permission declarations =="
python3 - <<'PY'
import pathlib, re
for p in sorted(pathlib.Path('.github/workflows').glob('*.ya*ml')):
    text=p.read_text()
    print(f'--- {p} ---')
    # extract workflow-level and job-level permissions blocks conservatively by indentation,
    # then print occurrences to keep focused.
    lines=text.splitlines()
    for i,l in enumerate(lines,1):
        if re.match(r'^(\s*)permissions:', l):
            indent=len(l)-len(l.lstrip())
            block=[l]
            j=i
            while j < len(lines):
                nxt=lines[j]
                if re.match(r'^(\s*)\S', nxt) and len(nxt)-len(nxt.lstrip()) <= indent and nxt.strip() != l.strip():
                    break
                j += 1
                block.append(lines[j]) if j <= len(lines) else None
            for k,line in enumerate(block):
                print(f'{i+k}: {line}')
PY

echo
echo "== default permissions in repository config =="
rg -n "permissions:|GITHUB_TOKEN" .github/workflows || true
git ls-files .github/workflows | sort

Repository: ruflin/Elastica

Length of output: 216


🌐 Web query:

GitHub Actions workflow syntax permissions contents read job permissions actions set permissions for GITHUB_TOKEN

💡 Result:

In GitHub Actions, you can configure the permissions granted to the GITHUB_TOKEN using the permissions key in your workflow file [1][2]. This allows you to follow the principle of least privilege by granting only the minimum access required for your jobs [2][3]. Permissions can be defined at two levels: 1. Workflow level: If specified at the top level of the YAML file, the permissions apply to all jobs within the workflow [1][4]. 2. Job level: If specified within a specific job, these permissions override any workflow-level settings for that job [1][4]. When you use the permissions key, any permissions not explicitly listed are set to none [1][3]. For example, if you set only contents: read, all other permissions (such as actions, issues, or packages) will have no access [1][4][3]. Example syntax for setting contents: read: jobs: job_id: runs-on: ubuntu-latest permissions: contents: read steps: - uses: actions/checkout@v4 The contents: read setting is commonly used to allow the workflow to clone or fetch the repository code [5][6]. If your workflow requires additional actions, such as pushing changes or creating releases, you must explicitly set the necessary permissions to write [6]. Key points to remember: - write permissions include read permissions [1]. - If you do not define the permissions key, GitHub applies the default permissions for the repository [6]. - Pull requests from public forks are a special case; they receive a read-only token regardless of these settings [3]. For a complete list of available scopes (such as actions, checks, deployments, packages, etc.), refer to the official GitHub Actions workflow syntax documentation [1][3].

Citations:


🏁 Script executed:

#!/bin/sh
set -euo pipefail

echo "== workflow excerpt =="
awk '{printf "%6d  %s\n", NR, $0}' .github/workflows/continuous-integration.yaml | sed -n '1,160p'

echo
echo "== all local workflow permission declarations =="
python3 - <<'PY'
import pathlib, re
pdir = pathlib.Path('.github/workflows')
pdir.mkdir(parents=True, exist_ok=True)
for p in sorted(pdir.glob('*.yml')) + sorted(pdir.glob('*.yaml')):
    text = p.read_text()
    print(f'--- {p} ---')
    lines = text.splitlines()
    for i, l in enumerate(lines, 1):
        if re.match(r'^(\s*)permissions:', l):
            indent = len(l) - len(l.lstrip())
            block = [l]
            j = i
            while j < len(lines):
                nxt = lines[j]
                if re.match(r'^(\s*)\S', nxt) and len(nxt) - len(nxt.lstrip()) <= indent and nxt.strip() != l.strip():
                    break
                j += 1
                if j <= len(lines):
                    block.append(lines[j])
            for k, line in enumerate(block):
                print(f'{i+k}: {line}')
PY

echo
echo "== GITHUB_TOKEN / permissions occurrences =="
grep -RInE 'permissions:|GITHUB_TOKEN' .github/workflows || true
git ls-files .github/workflows | sort

Repository: ruflin/Elastica

Length of output: 7313


Declare minimal permissions for the audit job.

continuous-integration.yaml has no workflow-level permissions, so this job inherits the repository’s default GITHUB_TOKEN permissions while executing external actions. Set contents: read here; unlisted permissions will be none.

🧰 Tools
🪛 zizmor (1.28.0)

[warning] 9-29: overly broad permissions (excessive-permissions): default permissions used due to no permissions: block

(excessive-permissions)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/continuous-integration.yaml around lines 9 - 11, Update
the audit job configuration in continuous-integration.yaml to declare minimal
GITHUB_TOKEN permissions, setting contents to read and leaving all unlisted
permissions disabled.

Source: Linters/SAST tools

steps:
- name: 'Checkout'
uses: 'actions/checkout@v4'

- name: 'Setup PHP'
uses: 'shivammathur/setup-php@v2'
with:
php-version: '8.4'
coverage: 'none'
tools: 'composer:v2'

- name: 'Install dependencies with Composer'
uses: 'ramsey/composer-install@v3'
Comment on lines +13 to +24

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "== workflow excerpt =="
sed -n '1,80p' .github/workflows/continuous-integration.yaml 2>/dev/null || true

echo
echo "== all action uses in workflows =="
rg -n "uses:\s*[^#]+" .github/workflows || true

echo
echo "== commit/tag refs in local repo =="
git rev-parse --symbolic-full-name HEAD HEAD^ 2>/dev/null || true
git show-ref --tags 2>/dev/null | head -40 || true

Repository: ruflin/Elastica

Length of output: 4246


🌐 Web query:

GitHub Actions secure use use full commit SHA branch tag mutable action security

💡 Result:

To secure GitHub Actions workflows against supply chain attacks, it is considered a critical best practice to pin all actions to a full-length (40-character) commit SHA [1][2][3][4][5]. Why Commit SHAs are Required for Security: - Immutability: Unlike branch names (e.g., @main, @master) or version tags (e.g., @v4), which are mutable pointers that can be moved or force-pushed to different commits by anyone with write access to the action's repository, a full commit SHA is cryptographically immutable [1][3][6][7]. - Mitigation of "Retargeting" Attacks: Using mutable references leaves your workflows vulnerable to malicious code injection if an action's repository or maintainer account is compromised [8][7][9]. An attacker can update an existing tag to point to malicious code, which would then be automatically executed by your workflows without any changes to your YAML files [2][6][7]. Pinning to a SHA prevents this entirely [2][3][10]. - Organizational Enforcement: GitHub now supports organization-level policies that can enforce full commit SHA pinning [11][2][9]. When enabled, workflows using mutable references will fail, ensuring compliance across an entire organization [11][2]. Best Practices for Implementation: - Pinning Format: Always use the full 40-character commit SHA [1][3]. - Maintain Readability: To maintain clarity and support automated updates, include the human-readable version tag as a trailing comment in your workflow file [2][8][7]. Example: - uses: actions/checkout@b4ffde6 # v4.1.1 - Automate Updates: Use dependency management tools like Renovate or Dependabot to automate the maintenance of these pinned SHAs [2][3][8][7]. These tools can be configured to track the associated tags and open pull requests when new versions are released, allowing you to update your pins intentionally [2][8][10]. - Transitive Security: Be aware that the security policy applies to the entire dependency tree. If you maintain an action that uses other actions internally, ensure those sub-actions are also pinned to full commit SHAs [11][9]. - Adoption Cooldowns: To further reduce risk, some organizations adopt a "cooldown" period (e.g., 7-14 days) before updating to new pinned versions of actions, which helps catch malicious releases that are often detected quickly [9].

Citations:


🌐 Web query:

docs.github.com actions reference security hard coding commit SHA Actions

💡 Result:

Pinning GitHub Actions to a full-length commit SHA is a primary security best practice recommended by GitHub to ensure the immutability of the code executed in your workflows [1][2]. Key security considerations include: - Why it is required: Using mutable references like tags (e.g., @v1, @v4) or branch names (e.g., @main) allows the underlying code to be changed or updated silently, posing a supply-chain risk if an action's repository is compromised or a tag is moved [1][3][2]. Pinning to a full 40-character commit SHA ensures that the exact code you audited is the code that runs [4][2]. - Policy Enforcement: GitHub allows administrators to enforce SHA pinning at the repository, organization, and enterprise levels [1][5][6]. When this policy is enabled, any workflow attempting to use an action referenced by a mutable tag or branch will fail [7]. This policy applies to the entire action dependency tree, meaning any internal sub-actions referenced by an action must also be pinned to a SHA [7]. - Managing Updates: While SHA pinning provides immutability, it does not prevent you from keeping your actions up to date. The recommended practice is to pin the action to a full-length commit SHA while keeping the human-readable version as a comment (e.g., uses: actions/checkout@a1b2c3d4e5... # v4.2.0) [3][4]. Tools like Dependabot can track these version comments and automatically open pull requests to update the pinned SHA when a new release is available, providing both security and ease of maintenance [3][5][4]. - Warning against short SHAs: You should always use the full-length (40-character) commit SHA [1][4]. Shortened SHAs are insecure because they are vulnerable to collision attacks where a malicious user could craft a commit that matches the short SHA, leading to ambiguous or compromised references [2]. For detailed configuration steps, refer to GitHub's documentation on securing your workflows [1][6].

Citations:


Pin the actions to immutable commit SHAs.

.github/workflows/continuous-integration.yaml pins the audit job to mutable tags (actions/checkout@v4, shivammathur/setup-php@v2, and ramsey/composer-install@v3), so the job can run changed code without workflow changes. Use full 40-character commit SHAs with human-readable version comments, and keep Dependabot configured to update those pins.

🧰 Tools
🪛 GitHub Check: CodeQL

[warning] 17-17: Unpinned tag for a non-immutable Action in workflow or composite action
Unpinned 3rd party Action 'Continuous integration' step Uses Step uses 'shivammathur/setup-php' with ref 'v2', not a pinned commit hash


[warning] 24-24: Unpinned tag for a non-immutable Action in workflow or composite action
Unpinned 3rd party Action 'Continuous integration' step Uses Step uses 'ramsey/composer-install' with ref 'v3', not a pinned commit hash

🪛 zizmor (1.28.0)

[warning] 13-14: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false

(artipacked)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/continuous-integration.yaml around lines 13 - 24, Update
the Checkout, Setup PHP, and Install dependencies with Composer steps to
reference immutable 40-character commit SHAs instead of mutable version tags,
adding human-readable version comments for each pinned action. Preserve the
existing action configuration and keep the repository’s Dependabot settings
configured to update these pinned references.

Source: Linters/SAST tools

with:
composer-options: '--prefer-dist'

- name: 'Run composer audit'
run: composer audit --abandoned=report --no-interaction

cs:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
runs-on: 'ubuntu-24.04'
name: 'Coding style'
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed
### Fixed
### Security
* Added a `SECURITY.md` file describing the supported branches and the private vulnerability-disclosure process.
* Added a `composer audit` job to the CI pipeline so PRs surface known advisories early.
* Added a CodeQL workflow that runs `security-and-quality` queries on the repository's GitHub Actions on every push, pull request, and weekly on a schedule.
* Added Dependabot configuration to keep Composer, GitHub Actions, and Docker dependencies up to date.
* Added a workflow `concurrency` group to cancel in-progress runs when a new commit lands on the same pull request.
Comment on lines +20 to +24


## [9.0.0](https://github.com/ruflin/Elastica/compare/8.x...9.0.0)
Expand Down
54 changes: 54 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Security Policy

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Remove the SECURITY.md file


## Supported Versions

Security fixes are provided for the latest minor release of each supported
major version. The supported branches at any time mirror the
[Elasticsearch end-of-life schedule](https://www.elastic.co/support/eol).

| Branch | Elasticsearch | PHP | Status |
|--------|---------------|------------|-----------------------|
| 9.x | 9.x | 8.1 – 8.5 | Active development |
| 8.x | 8.x | 8.0 – 8.3 | Security fixes only |
| 7.x | 7.x | 7.2+ | End of life |
| 6.x | 6.x | 7.0+ | End of life |

Anything older than 7.x is unmaintained.

## Reporting a Vulnerability

If you discover a security vulnerability in Elastica, **please do not open
a public GitHub issue**. Instead use one of the following private channels:

- Open a [GitHub Security Advisory](https://github.com/ruflin/Elastica/security/advisories/new)
on the repository (preferred).
- Or email the maintainer directly at `spam@ruflin.com` with the subject
prefix `[Elastica security]`.

Comment on lines +21 to +27
Please include:

- A description of the vulnerability and its impact.
- Steps to reproduce, ideally with a minimal proof of concept.
- The Elastica version and PHP version you tested against.
- Any suggested mitigation, if available.

You can expect an initial acknowledgement within **5 business days** and a
coordinated disclosure window of up to **90 days** while a fix is prepared
and released. Credits are given in the release notes unless you ask to
remain anonymous.

## Scope

The following are in scope:

- Code published as part of the [`ruflin/elastica`](https://packagist.org/packages/ruflin/elastica)
Composer package.
- Continuous-integration workflows and reusable scripts shipped with the
repository.

Out of scope:

- Vulnerabilities in third-party dependencies (please report those upstream
to their maintainers); we will track and bump impacted versions once a
fix is available there.
- Vulnerabilities in user code that incorrectly uses Elastica.
Loading