Compare commits

..
Author SHA1 Message Date
stumpylog 1b2b635090 Chore(deps): Raise Python dependency constraints
Raise the upper bounds holding back celery, imap-tools, torch, turbohtml, faker, pytest and pytest-randomly, and take a few patch releases.
2026-12-01 13:09:17 -08:00
stumpylog 9a6b0b092f Chore(deps): Update Python dependencies by hand
Dependabot's Python updates are not running, so bump the low risk packages, including the Django 5.2.19 security release, with uv lock --upgrade-package.
2026-12-01 13:09:17 -08:00
dependabot[bot] 3f5d14bf05 Chore(deps): Bump the pre-commit-dependencies group with 3 updates (#14930)
Bumps the pre-commit-dependencies group with 3 updates: [https://github.com/rbubley/mirrors-prettier](https://github.com/rbubley/mirrors-prettier), prettier and [https://github.com/tox-dev/pyproject-fmt](https://github.com/tox-dev/pyproject-fmt).


Updates `https://github.com/rbubley/mirrors-prettier` from v3.9.10 to 3.10.1
- [Commits](https://github.com/rbubley/mirrors-prettier/compare/v3.9.10...v3.10.1)

Updates `prettier` from 3.9.10 to 3.10.1

Updates `https://github.com/tox-dev/pyproject-fmt` from v2.30.3 to 2.31.2
- [Release notes](https://github.com/tox-dev/pyproject-fmt/releases)
- [Commits](https://github.com/tox-dev/pyproject-fmt/compare/v2.30.3...v2.31.2)

---
updated-dependencies:
- dependency-name: https://github.com/rbubley/mirrors-prettier
  dependency-version: 3.10.1
  dependency-type: direct:production
  dependency-group: pre-commit-dependencies
- dependency-name: prettier
  dependency-version: 3.10.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: pre-commit-dependencies
- dependency-name: https://github.com/tox-dev/pyproject-fmt
  dependency-version: 2.31.2
  dependency-type: direct:production
  dependency-group: pre-commit-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-12-01 17:41:38 +00:00
dependabot[bot] aa44ff75e1 Chore(deps): Bump the actions group across 1 directory with 10 updates (#14931)
Bumps the actions group with 10 updates in the / directory:

| Package | From | To |
| --- | --- | --- |
| [astral-sh/setup-uv](https://github.com/astral-sh/setup-uv) | `10.3.3` | `10.4.0` |
| [docker/login-action](https://github.com/docker/login-action) | `4.7.0` | `4.8.0` |
| [pnpm/action-setup](https://github.com/pnpm/action-setup) | `6.1.0` | `6.1.1` |
| [j178/prek-action](https://github.com/j178/prek-action) | `3.1.0` | `3.1.1` |
| [release-drafter/release-drafter](https://github.com/release-drafter/release-drafter) | `7.10.0` | `7.11.0` |
| [zizmorcore/zizmor-action](https://github.com/zizmorcore/zizmor-action) | `0.8.0` | `0.9.2` |
| [github/codeql-action/upload-sarif](https://github.com/github/codeql-action) | `4.39.1` | `4.39.4` |
| [github/codeql-action/init](https://github.com/github/codeql-action) | `4.39.1` | `4.39.4` |
| [github/codeql-action/analyze](https://github.com/github/codeql-action) | `4.39.1` | `4.39.4` |
| [crowdin/github-action](https://github.com/crowdin/github-action) | `3.5.0` | `3.6.0` |



Updates `astral-sh/setup-uv` from 10.3.3 to 10.4.0
- [Release notes](https://github.com/astral-sh/setup-uv/releases)
- [Commits](https://github.com/astral-sh/setup-uv/compare/68559e99cc807c1eb7e9238fd43a15bba460eec2...1db35dd8eee11c5894872e0b383ae6c406cf738d)

Updates `docker/login-action` from 4.7.0 to 4.8.0
- [Release notes](https://github.com/docker/login-action/releases)
- [Commits](https://github.com/docker/login-action/compare/81c6f93d4bc991e510b342a00b419b3bb4efc5c6...8aa5831fb8d48d8f76594c7ddde61ae58019f550)

Updates `pnpm/action-setup` from 6.1.0 to 6.1.1
- [Release notes](https://github.com/pnpm/action-setup/releases)
- [Commits](https://github.com/pnpm/action-setup/compare/ea17c68df8912ef543352723c149a84f56e3d413...73e46992e05b19abd31f2f3c20e0e7370d762115)

Updates `j178/prek-action` from 3.1.0 to 3.1.1
- [Release notes](https://github.com/j178/prek-action/releases)
- [Commits](https://github.com/j178/prek-action/compare/44924fe9ef4a6f88253c4b6b1bf11c689d3ce53d...7b101f8338a08d2bd6fdb3625e4e7692428763a3)

Updates `release-drafter/release-drafter` from 7.10.0 to 7.11.0
- [Release notes](https://github.com/release-drafter/release-drafter/releases)
- [Commits](https://github.com/release-drafter/release-drafter/compare/978bb0b30c5ee8cdd332ced253758157150d43f0...d1a19e60e81a7e650d00a7de9277f87e439117ea)

Updates `zizmorcore/zizmor-action` from 0.8.0 to 0.9.2
- [Release notes](https://github.com/zizmorcore/zizmor-action/releases)
- [Commits](https://github.com/zizmorcore/zizmor-action/compare/53290badfa369cb0bf7ad16342cb62c2fa47ac7b...1b4550e929643b8b26a62303c6bd64814271a4f1)

Updates `github/codeql-action/upload-sarif` from 4.39.1 to 4.39.4
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/9b3254085494b55a0f7c4c2b3d2d52cc712ce370...1bd86f2fdb4b86187fa4059f16f31a3202acc9ea)

Updates `github/codeql-action/init` from 4.39.1 to 4.39.4
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/9b3254085494b55a0f7c4c2b3d2d52cc712ce370...1bd86f2fdb4b86187fa4059f16f31a3202acc9ea)

Updates `github/codeql-action/analyze` from 4.39.1 to 4.39.4
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/9b3254085494b55a0f7c4c2b3d2d52cc712ce370...1bd86f2fdb4b86187fa4059f16f31a3202acc9ea)

Updates `crowdin/github-action` from 3.5.0 to 3.6.0
- [Release notes](https://github.com/crowdin/github-action/releases)
- [Commits](https://github.com/crowdin/github-action/compare/959dc74ac104447731cba99a016f85d0ae719788...d651c77756acbe11a31d77a6fb79d8a239e1e05a)

---
updated-dependencies:
- dependency-name: astral-sh/setup-uv
  dependency-version: 10.4.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: actions
- dependency-name: crowdin/github-action
  dependency-version: 3.6.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: actions
- dependency-name: docker/login-action
  dependency-version: 4.8.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: actions
- dependency-name: github/codeql-action/analyze
  dependency-version: 4.39.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: actions
- dependency-name: github/codeql-action/init
  dependency-version: 4.39.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: actions
- dependency-name: github/codeql-action/upload-sarif
  dependency-version: 4.39.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: actions
- dependency-name: j178/prek-action
  dependency-version: 3.1.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: actions
- dependency-name: pnpm/action-setup
  dependency-version: 6.1.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: actions
- dependency-name: release-drafter/release-drafter
  dependency-version: 7.11.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: actions
- dependency-name: zizmorcore/zizmor-action
  dependency-version: 0.9.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-12-01 17:27:56 +00:00
Trenton H b783d5e895 Fix: sign cache entries so values planted in Redis are never unpickled (#14950)
* Fix: sign cache entries so values planted in Redis are never unpickled

* Guards against the small window where the suggestion cache could return a version and a None from get_many
2026-12-01 16:42:02 +00:00
dependabot[bot] 3c295be9b4 docker-compose(deps): Bump nginx in /docker/compose (#14928)
Bumps nginx from 1.31.7-alpine to 1.31.9-alpine.

---
updated-dependencies:
- dependency-name: nginx
  dependency-version: 1.31.9-alpine
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-12-01 07:54:03 -08:00
22 changed files with 764 additions and 897 deletions

No files matched your search

+2 -2
View File
@@ -104,7 +104,7 @@ jobs:
with: with:
python-version: "${{ matrix.python-version }}" python-version: "${{ matrix.python-version }}"
- name: Install uv - name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with: with:
version: ${{ env.DEFAULT_UV_VERSION }} version: ${{ env.DEFAULT_UV_VERSION }}
enable-cache: true enable-cache: true
@@ -174,7 +174,7 @@ jobs:
with: with:
python-version: "${{ env.DEFAULT_PYTHON }}" python-version: "${{ env.DEFAULT_PYTHON }}"
- name: Install uv - name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with: with:
version: ${{ env.DEFAULT_UV_VERSION }} version: ${{ env.DEFAULT_UV_VERSION }}
enable-cache: true enable-cache: true
+4 -4
View File
@@ -109,7 +109,7 @@ jobs:
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- name: Login to GitHub Container Registry - name: Login to GitHub Container Registry
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4.7.0 uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0
with: with:
registry: ${{ env.REGISTRY }} registry: ${{ env.REGISTRY }}
username: ${{ github.actor }} username: ${{ github.actor }}
@@ -185,20 +185,20 @@ jobs:
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- name: Login to GitHub Container Registry - name: Login to GitHub Container Registry
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4.7.0 uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0
with: with:
registry: ${{ env.REGISTRY }} registry: ${{ env.REGISTRY }}
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker Hub - name: Login to Docker Hub
if: needs.build-arch.outputs.push-external == 'true' if: needs.build-arch.outputs.push-external == 'true'
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4.7.0 uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0
with: with:
username: ${{ secrets.DOCKERHUB_USERNAME }} username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }} password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to Quay.io - name: Login to Quay.io
if: needs.build-arch.outputs.push-external == 'true' if: needs.build-arch.outputs.push-external == 'true'
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4.7.0 uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0
with: with:
registry: quay.io registry: quay.io
username: ${{ secrets.QUAY_USERNAME }} username: ${{ secrets.QUAY_USERNAME }}
+1 -1
View File
@@ -79,7 +79,7 @@ jobs:
with: with:
python-version: ${{ env.DEFAULT_PYTHON_VERSION }} python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
- name: Install uv - name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with: with:
version: ${{ env.DEFAULT_UV_VERSION }} version: ${{ env.DEFAULT_UV_VERSION }}
enable-cache: true enable-cache: true
+6 -6
View File
@@ -83,7 +83,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
- name: Install pnpm - name: Install pnpm
uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0 uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
with: with:
package_json_file: src-ui/package.json package_json_file: src-ui/package.json
- name: Use Node.js 24 - name: Use Node.js 24
@@ -115,7 +115,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
- name: Install pnpm - name: Install pnpm
uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0 uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
with: with:
package_json_file: src-ui/package.json package_json_file: src-ui/package.json
- name: Use Node.js 24 - name: Use Node.js 24
@@ -154,7 +154,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
- name: Install pnpm - name: Install pnpm
uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0 uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
with: with:
package_json_file: src-ui/package.json package_json_file: src-ui/package.json
- name: Use Node.js 24 - name: Use Node.js 24
@@ -203,7 +203,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
- name: Install pnpm - name: Install pnpm
uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0 uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
with: with:
package_json_file: src-ui/package.json package_json_file: src-ui/package.json
- name: Use Node.js 24 - name: Use Node.js 24
@@ -218,7 +218,7 @@ jobs:
with: with:
python-version: '3.12' python-version: '3.12'
- name: Install uv - name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with: with:
version: '0.13.x' version: '0.13.x'
enable-cache: false enable-cache: false
@@ -258,7 +258,7 @@ jobs:
fetch-depth: 2 fetch-depth: 2
persist-credentials: false persist-credentials: false
- name: Install pnpm - name: Install pnpm
uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0 uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
with: with:
package_json_file: src-ui/package.json package_json_file: src-ui/package.json
- name: Use Node.js 24 - name: Use Node.js 24
+1 -1
View File
@@ -26,4 +26,4 @@ jobs:
with: with:
python-version: "3.14" python-version: "3.14"
- name: Run prek - name: Run prek
uses: j178/prek-action@44924fe9ef4a6f88253c4b6b1bf11c689d3ce53d # v3.1.0 uses: j178/prek-action@7b101f8338a08d2bd6fdb3625e4e7692428763a3 # v3.1.1
+4 -4
View File
@@ -40,7 +40,7 @@ jobs:
persist-credentials: false persist-credentials: false
# ---- Frontend Build ---- # ---- Frontend Build ----
- name: Install pnpm - name: Install pnpm
uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0 uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
with: with:
package_json_file: src-ui/package.json package_json_file: src-ui/package.json
- name: Use Node.js 24 - name: Use Node.js 24
@@ -59,7 +59,7 @@ jobs:
with: with:
python-version: ${{ env.DEFAULT_PYTHON_VERSION }} python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
- name: Install uv - name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with: with:
version: ${{ env.DEFAULT_UV_VERSION }} version: ${{ env.DEFAULT_UV_VERSION }}
enable-cache: false enable-cache: false
@@ -172,7 +172,7 @@ jobs:
fi fi
- name: Create release and changelog - name: Create release and changelog
id: create-release id: create-release
uses: release-drafter/release-drafter@978bb0b30c5ee8cdd332ced253758157150d43f0 # v7.10.0 uses: release-drafter/release-drafter@d1a19e60e81a7e650d00a7de9277f87e439117ea # v7.11.0
with: with:
name: Paperless-ngx ${{ steps.get-version.outputs.version }} name: Paperless-ngx ${{ steps.get-version.outputs.version }}
tag: ${{ steps.get-version.outputs.version }} tag: ${{ steps.get-version.outputs.version }}
@@ -213,7 +213,7 @@ jobs:
with: with:
python-version: ${{ env.DEFAULT_PYTHON_VERSION }} python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
- name: Install uv - name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with: with:
version: ${{ env.DEFAULT_UV_VERSION }} version: ${{ env.DEFAULT_UV_VERSION }}
enable-cache: false enable-cache: false
+2 -2
View File
@@ -27,7 +27,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
- name: Run zizmor - name: Run zizmor
uses: zizmorcore/zizmor-action@53290badfa369cb0bf7ad16342cb62c2fa47ac7b # v0.8.0 uses: zizmorcore/zizmor-action@1b4550e929643b8b26a62303c6bd64814271a4f1 # v0.9.2
semgrep: semgrep:
name: Semgrep CE name: Semgrep CE
runs-on: ubuntu-26.04 runs-on: ubuntu-26.04
@@ -45,7 +45,7 @@ jobs:
- name: Run Semgrep - name: Run Semgrep
run: semgrep scan --config auto --sarif-output results.sarif run: semgrep scan --config auto --sarif-output results.sarif
- name: Upload results to GitHub code scanning - name: Upload results to GitHub code scanning
uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1 uses: github/codeql-action/upload-sarif@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea # v4.39.4
if: always() if: always()
with: with:
sarif_file: results.sarif sarif_file: results.sarif
+2 -2
View File
@@ -39,7 +39,7 @@ jobs:
persist-credentials: false persist-credentials: false
# Initializes the CodeQL tools for scanning. # Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL - name: Initialize CodeQL
uses: github/codeql-action/init@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1 uses: github/codeql-action/init@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea # v4.39.4
with: with:
languages: ${{ matrix.language }} languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file. # If you wish to specify custom queries, you can do so here or in a config file.
@@ -47,4 +47,4 @@ jobs:
# Prefix the list here with "+" to use these queries and those in the config file. # Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main # queries: ./path/to/local/query, your-org/your-repo/queries@main
- name: Perform CodeQL Analysis - name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1 uses: github/codeql-action/analyze@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea # v4.39.4
+1 -1
View File
@@ -22,7 +22,7 @@ jobs:
token: ${{ secrets.PNGX_BOT_PAT }} token: ${{ secrets.PNGX_BOT_PAT }}
persist-credentials: false persist-credentials: false
- name: crowdin action - name: crowdin action
uses: crowdin/github-action@959dc74ac104447731cba99a016f85d0ae719788 # v3.5.0 uses: crowdin/github-action@d651c77756acbe11a31d77a6fb79d8a239e1e05a # v3.6.0
with: with:
upload_translations: false upload_translations: false
download_translations: true download_translations: true
+1 -1
View File
@@ -19,6 +19,6 @@ jobs:
if: github.event_name == 'pull_request_target' && (github.event.action == 'opened' || github.event.action == 'reopened') && github.event.pull_request.user.login != 'dependabot' if: github.event_name == 'pull_request_target' && (github.event.action == 'opened' || github.event.action == 'reopened') && github.event.pull_request.user.login != 'dependabot'
steps: steps:
- name: Label PR with release-drafter - name: Label PR with release-drafter
uses: release-drafter/release-drafter@978bb0b30c5ee8cdd332ced253758157150d43f0 # v7.10.0 uses: release-drafter/release-drafter@d1a19e60e81a7e650d00a7de9277f87e439117ea # v7.11.0
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+2 -2
View File
@@ -30,7 +30,7 @@ jobs:
with: with:
packages: gettext packages: gettext
- name: Install uv - name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with: with:
version: ${{ env.DEFAULT_UV_VERSION }} version: ${{ env.DEFAULT_UV_VERSION }}
enable-cache: true enable-cache: true
@@ -44,7 +44,7 @@ jobs:
PAPERLESS_SECRET_KEY: "ci-translate-not-a-real-secret" PAPERLESS_SECRET_KEY: "ci-translate-not-a-real-secret"
run: cd src/ && uv run manage.py makemessages -l en_US -i "samples*" run: cd src/ && uv run manage.py makemessages -l en_US -i "samples*"
- name: Install pnpm - name: Install pnpm
uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0 uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
with: with:
package_json_file: src-ui/package.json package_json_file: src-ui/package.json
- name: Use Node.js 24 - name: Use Node.js 24
+3 -3
View File
@@ -38,7 +38,7 @@ repos:
- json - json
# See https://github.com/prettier/prettier/issues/15742 for the fork reason # See https://github.com/prettier/prettier/issues/15742 for the fork reason
- repo: https://github.com/rbubley/mirrors-prettier - repo: https://github.com/rbubley/mirrors-prettier
rev: 'v3.9.10' rev: 'v3.10.1'
hooks: hooks:
- id: prettier - id: prettier
types_or: types_or:
@@ -46,7 +46,7 @@ repos:
- ts - ts
- markdown - markdown
additional_dependencies: additional_dependencies:
- prettier@3.9.10 - prettier@3.10.1
- 'prettier-plugin-organize-imports@4.3.0' - 'prettier-plugin-organize-imports@4.3.0'
# Python hooks # Python hooks
- repo: https://github.com/astral-sh/ruff-pre-commit - repo: https://github.com/astral-sh/ruff-pre-commit
@@ -55,7 +55,7 @@ repos:
- id: ruff-check - id: ruff-check
- id: ruff-format - id: ruff-format
- repo: https://github.com/tox-dev/pyproject-fmt - repo: https://github.com/tox-dev/pyproject-fmt
rev: "v2.30.3" rev: "v2.31.2"
hooks: hooks:
- id: pyproject-fmt - id: pyproject-fmt
additional_dependencies: [tomli] additional_dependencies: [tomli]
+1 -1
View File
@@ -35,7 +35,7 @@ services:
- "3143:3143" # IMAP - "3143:3143" # IMAP
restart: unless-stopped restart: unless-stopped
nginx: nginx:
image: docker.io/nginx:1.31.7-alpine image: docker.io/nginx:1.31.9-alpine
hostname: nginx hostname: nginx
container_name: nginx container_name: nginx
ports: ports:
+8 -8
View File
@@ -19,7 +19,7 @@ classifiers = [
dependencies = [ dependencies = [
"azure-ai-documentintelligence>=1.0.2", "azure-ai-documentintelligence>=1.0.2",
"babel>=2.17", "babel>=2.17",
"celery[redis]~=5.6.2", "celery[redis]~=5.7.0",
"channels~=4.2", "channels~=4.2",
"channels-redis~=4.2", "channels-redis~=4.2",
"concurrent-log-handler~=0.9.25", "concurrent-log-handler~=0.9.25",
@@ -27,7 +27,7 @@ dependencies = [
"dateparser~=1.4", "dateparser~=1.4",
# WARNING: django does not use semver. # WARNING: django does not use semver.
# Only patch versions are guaranteed to not introduce breaking changes. # Only patch versions are guaranteed to not introduce breaking changes.
"django~=5.2.18", "django~=5.2.19",
"django-allauth[mfa,socialaccount]~=65.21.1", "django-allauth[mfa,socialaccount]~=65.21.1",
"django-auditlog~=3.4.1", "django-auditlog~=3.4.1",
"django-cachalot~=2.9.0", "django-cachalot~=2.9.0",
@@ -49,7 +49,7 @@ dependencies = [
"httpx-oauth~=0.17", "httpx-oauth~=0.17",
"humanize>=4.15", "humanize>=4.15",
"ijson>=3.5.1", "ijson>=3.5.1",
"imap-tools>=1.14,<1.16", "imap-tools>=1.14,<1.17",
"jinja2~=3.1.6", "jinja2~=3.1.6",
"langdetect~=1.0.9", "langdetect~=1.0.9",
"llama-index-core>=0.14.23", "llama-index-core>=0.14.23",
@@ -79,8 +79,8 @@ dependencies = [
"sqlite-vec==0.1.10+paperless.3", "sqlite-vec==0.1.10+paperless.3",
"tantivy~=0.26.0", "tantivy~=0.26.0",
"tika-client[httpx]~=1.0", "tika-client[httpx]~=1.0",
"torch>=2.13,<2.15", "torch>=2.13,<2.16",
"turbohtml~=1.15.3", "turbohtml~=1.16.0",
"watchfiles>=1.2", "watchfiles>=1.2",
"whitenoise~=6.11", "whitenoise~=6.11",
"whoosh-compat[tantivy]==0.3", "whoosh-compat[tantivy]==0.3",
@@ -116,15 +116,15 @@ lint = [
testing = [ testing = [
"daphne", "daphne",
"factory-boy~=3.3.1", "factory-boy~=3.3.1",
"faker>=40.36,<40.44", "faker>=40.36,<40.64",
"imagehash", "imagehash",
"pytest~=9.1.1", "pytest~=9.2.0",
"pytest-cov~=7.1.0", "pytest-cov~=7.1.0",
"pytest-django>=4.12,<4.15", "pytest-django>=4.12,<4.15",
"pytest-env~=1.8.1", "pytest-env~=1.8.1",
"pytest-httpx", "pytest-httpx",
"pytest-mock~=3.17.0", "pytest-mock~=3.17.0",
"pytest-randomly~=5.0.0", "pytest-randomly~=5.1.0",
"pytest-rerunfailures~=16.4", "pytest-rerunfailures~=16.4",
"pytest-sugar", "pytest-sugar",
"pytest-xdist~=3.8.0", "pytest-xdist~=3.8.0",
+4 -3
View File
@@ -73,9 +73,10 @@ def get_suggestion_cache(document_id: int) -> SuggestionCacheData | None:
doc_key = get_suggestion_cache_key(document_id) doc_key = get_suggestion_cache_key(document_id)
cache_hits = cache.get_many([CLASSIFIER_VERSION_KEY, CLASSIFIER_HASH_KEY, doc_key]) cache_hits = cache.get_many([CLASSIFIER_VERSION_KEY, CLASSIFIER_HASH_KEY, doc_key])
# The document suggestions are in the cache # The document suggestions are in the cache. get_many keeps an entry the cache
if doc_key in cache_hits: # serializer rejected as None, rather than leaving the key out.
doc_suggestions: SuggestionCacheData = cache_hits[doc_key] doc_suggestions: SuggestionCacheData | None = cache_hits.get(doc_key)
if doc_suggestions is not None:
# The classifier format is the same # The classifier format is the same
# The classifier hash is the same # The classifier hash is the same
# Then the suggestions can be used # Then the suggestions can be used
+14 -62
View File
@@ -3238,14 +3238,10 @@ class WorkflowTriggerSerializer(serializers.ModelSerializer[WorkflowTrigger]):
] ]
def create(self, validated_data): def create(self, validated_data):
# The id is only meaningful when this is nested in a workflow. On its own
# a client chosen id would collide with, or overwrite, another row
validated_data.pop("id", None)
WorkflowTriggerSerializer.normalize_workflow_trigger_sources(validated_data) WorkflowTriggerSerializer.normalize_workflow_trigger_sources(validated_data)
return super().create(validated_data) return super().create(validated_data)
def update(self, instance, validated_data): def update(self, instance, validated_data):
validated_data.pop("id", None)
WorkflowTriggerSerializer.normalize_workflow_trigger_sources(validated_data) WorkflowTriggerSerializer.normalize_workflow_trigger_sources(validated_data)
return super().update(instance, validated_data) return super().update(instance, validated_data)
@@ -3287,34 +3283,6 @@ class WorkflowActionWebhookSerializer(
] ]
def save_action_email_and_webhook(action, email_data, webhook_data) -> None:
"""
Store the nested email and webhook of a workflow action on the action's own rows.
An id in the payload is never used, it could name a row that belongs to another
action. An action with no row of that kind gets a new one. The data must already
be cleaned by the nested serializers, an unknown key would be a model error.
"""
created = False
for data, model, attribute in (
(email_data, WorkflowActionEmail, "email"),
(webhook_data, WorkflowActionWebhook, "webhook"),
):
if data is None:
continue
values = {key: value for key, value in data.items() if key != "id"}
existing = getattr(action, attribute)
if existing is not None:
# Change the loaded row, a response is built from it
for key, value in values.items():
setattr(existing, key, value)
existing.save()
else:
setattr(action, attribute, model.objects.create(**values))
created = True
if created:
action.save()
class WorkflowActionSerializer(serializers.ModelSerializer[WorkflowAction]): class WorkflowActionSerializer(serializers.ModelSerializer[WorkflowAction]):
id = serializers.IntegerField(required=False, allow_null=True) id = serializers.IntegerField(required=False, allow_null=True)
assign_correspondent = CorrespondentField(allow_null=True, required=False) assign_correspondent = CorrespondentField(allow_null=True, required=False)
@@ -3366,22 +3334,6 @@ class WorkflowActionSerializer(serializers.ModelSerializer[WorkflowAction]):
"ai_overwrite_existing", "ai_overwrite_existing",
] ]
def create(self, validated_data):
validated_data.pop("id", None)
email_data = validated_data.pop("email", None)
webhook_data = validated_data.pop("webhook", None)
instance = super().create(validated_data)
save_action_email_and_webhook(instance, email_data, webhook_data)
return instance
def update(self, instance, validated_data):
validated_data.pop("id", None)
email_data = validated_data.pop("email", None)
webhook_data = validated_data.pop("webhook", None)
instance = super().update(instance, validated_data)
save_action_email_and_webhook(instance, email_data, webhook_data)
return instance
def validate(self, attrs): def validate(self, attrs):
if "assign_title" in attrs and attrs["assign_title"] is not None: if "assign_title" in attrs and attrs["assign_title"] is not None:
if len(attrs["assign_title"]) == 0: if len(attrs["assign_title"]) == 0:
@@ -3544,10 +3496,6 @@ class WorkflowSerializer(serializers.ModelSerializer[Workflow]):
) -> None: ) -> None:
set_triggers = [] set_triggers = []
set_actions = [] set_actions = []
# Only rows already attached to this workflow may be updated by id, an id
# from anywhere else would take over or overwrite another workflow's row
own_trigger_ids = set(instance.triggers.values_list("pk", flat=True))
own_action_ids = set(instance.actions.values_list("pk", flat=True))
if triggers is not None and triggers is not serializers.empty: if triggers is not None and triggers is not serializers.empty:
for trigger in triggers: for trigger in triggers:
@@ -3580,10 +3528,8 @@ class WorkflowSerializer(serializers.ModelSerializer[Workflow]):
) )
# Convert sources to strings to handle django-multiselectfield v1.0 changes # Convert sources to strings to handle django-multiselectfield v1.0 changes
WorkflowTriggerSerializer.normalize_workflow_trigger_sources(trigger) WorkflowTriggerSerializer.normalize_workflow_trigger_sources(trigger)
trigger_id = trigger.pop("id", None)
trigger_instance, _ = WorkflowTrigger.objects.update_or_create( trigger_instance, _ = WorkflowTrigger.objects.update_or_create(
# A row that is not already part of this workflow is never reused id=trigger.get("id"),
id=trigger_id if trigger_id in own_trigger_ids else None,
defaults=trigger, defaults=trigger,
) )
if filter_has_tags is not None: if filter_has_tags is not None:
@@ -3641,24 +3587,30 @@ class WorkflowSerializer(serializers.ModelSerializer[Workflow]):
email_data = action.pop("email", None) email_data = action.pop("email", None)
webhook_data = action.pop("webhook", None) webhook_data = action.pop("webhook", None)
action_id = action.pop("id", None)
action_instance, _ = WorkflowAction.objects.update_or_create( action_instance, _ = WorkflowAction.objects.update_or_create(
# A row that is not already part of this workflow is never reused id=action.get("id"),
id=action_id if action_id in own_action_ids else None,
defaults=action, defaults=action,
) )
if email_data is not None: if email_data is not None:
serializer = WorkflowActionEmailSerializer(data=email_data) serializer = WorkflowActionEmailSerializer(data=email_data)
serializer.is_valid(raise_exception=True) serializer.is_valid(raise_exception=True)
email_data = serializer.validated_data email, _ = WorkflowActionEmail.objects.update_or_create(
id=email_data.get("id"),
defaults=serializer.validated_data,
)
action_instance.email = email
action_instance.save()
if webhook_data is not None: if webhook_data is not None:
serializer = WorkflowActionWebhookSerializer(data=webhook_data) serializer = WorkflowActionWebhookSerializer(data=webhook_data)
serializer.is_valid(raise_exception=True) serializer.is_valid(raise_exception=True)
webhook_data = serializer.validated_data webhook, _ = WorkflowActionWebhook.objects.update_or_create(
id=webhook_data.get("id"),
save_action_email_and_webhook(action_instance, email_data, webhook_data) defaults=serializer.validated_data,
)
action_instance.webhook = webhook
action_instance.save()
if assign_tags is not None: if assign_tags is not None:
action_instance.assign_tags.set(assign_tags) action_instance.assign_tags.set(assign_tags)
@@ -1,308 +0,0 @@
import json
from django.http import HttpResponse
from rest_framework import status
from rest_framework.test import APIClient
from documents.models import WorkflowAction
from documents.models import WorkflowActionEmail
from documents.models import WorkflowTrigger
EMAIL = {
"subject": "original",
"body": "body",
"to": "someone@example.com",
"include_document": False,
}
def workflow_body(name: str, *, trigger: dict, action: dict) -> dict:
return {
"name": name,
"order": 0,
"enabled": True,
"triggers": [
{"type": 2, "sources": [1], "matching_algorithm": 0, **trigger},
],
"actions": [{"type": 3, "email": EMAIL, **action}],
}
def send_json(client: APIClient, method: str, path: str, body: object) -> HttpResponse:
return client.generic(
method,
path,
data=json.dumps(body),
content_type="application/json",
)
def make_workflow(client: APIClient, name: str) -> dict:
response = send_json(
client,
"POST",
"/api/workflows/",
workflow_body(name, trigger={}, action={}),
)
assert response.status_code == status.HTTP_201_CREATED
return response.data
class TestWorkflowRowOwnership:
def test_update_cannot_take_over_another_workflows_action(
self,
admin_client: APIClient,
) -> None:
"""
GIVEN:
- Two workflows, each with an email action
WHEN:
- The first is updated with the id of the second one's action and a changed
email
THEN:
- The second workflow's action and email are untouched, the first gets its
own action
"""
first = make_workflow(admin_client, "first")
second = make_workflow(admin_client, "second")
foreign_action = second["actions"][0]
foreign_email_id = foreign_action["email"]["id"]
response = send_json(
admin_client,
"PUT",
f"/api/workflows/{first['id']}/",
workflow_body(
"first",
trigger={"id": first["triggers"][0]["id"]},
action={
"id": foreign_action["id"],
"email": {**EMAIL, "subject": "taken over"},
},
),
)
assert response.status_code == status.HTTP_200_OK
assert response.data["actions"][0]["id"] != foreign_action["id"]
assert WorkflowActionEmail.objects.get(pk=foreign_email_id).subject == (
"original"
)
second_actions = list(
WorkflowAction.objects.filter(workflows__pk=second["id"]),
)
assert [a.pk for a in second_actions] == [foreign_action["id"]]
def test_update_cannot_take_over_another_workflows_trigger(
self,
admin_client: APIClient,
) -> None:
"""
GIVEN:
- Two workflows
WHEN:
- The first is updated with the id of the second one's trigger and a
different filter
THEN:
- The second workflow's trigger is untouched
"""
first = make_workflow(admin_client, "first")
second = make_workflow(admin_client, "second")
foreign_trigger_id = second["triggers"][0]["id"]
response = send_json(
admin_client,
"PUT",
f"/api/workflows/{first['id']}/",
workflow_body(
"first",
trigger={"id": foreign_trigger_id, "filter_filename": "taken"},
action={"id": first["actions"][0]["id"]},
),
)
assert response.status_code == status.HTTP_200_OK
assert response.data["triggers"][0]["id"] != foreign_trigger_id
assert WorkflowTrigger.objects.get(pk=foreign_trigger_id).filter_filename != (
"taken"
)
assert list(
WorkflowTrigger.objects.filter(workflows__pk=second["id"]).values_list(
"pk",
flat=True,
),
) == [foreign_trigger_id]
def test_nested_email_id_of_another_action_is_ignored(
self,
admin_client: APIClient,
) -> None:
"""
GIVEN:
- Two workflows with email actions
WHEN:
- The first is updated, keeping its own action, with the second action's
email id in the nested email
THEN:
- The other email is untouched and the action's own email is the one
changed
"""
first = make_workflow(admin_client, "first")
second = make_workflow(admin_client, "second")
own_action = first["actions"][0]
own_email_id = own_action["email"]["id"]
foreign_email_id = second["actions"][0]["email"]["id"]
response = send_json(
admin_client,
"PUT",
f"/api/workflows/{first['id']}/",
workflow_body(
"first",
trigger={"id": first["triggers"][0]["id"]},
action={
"id": own_action["id"],
"email": {**EMAIL, "id": foreign_email_id, "subject": "mine"},
},
),
)
assert response.status_code == status.HTTP_200_OK
assert WorkflowActionEmail.objects.get(pk=foreign_email_id).subject == (
"original"
)
assert response.data["actions"][0]["email"]["id"] == own_email_id
assert WorkflowActionEmail.objects.get(pk=own_email_id).subject == "mine"
def test_nested_email_id_beyond_the_database_range_is_ignored(
self,
admin_client: APIClient,
) -> None:
"""
GIVEN:
- A workflow with an email action
WHEN:
- It is updated with a nested email id larger than a column can hold
THEN:
- The request succeeds and the action keeps its own email row
"""
workflow = make_workflow(admin_client, "workflow")
action = workflow["actions"][0]
response = send_json(
admin_client,
"PUT",
f"/api/workflows/{workflow['id']}/",
workflow_body(
"workflow",
trigger={"id": workflow["triggers"][0]["id"]},
action={
"id": action["id"],
"email": {**EMAIL, "id": 2**63},
},
),
)
assert response.status_code == status.HTTP_200_OK
assert response.data["actions"][0]["email"]["id"] == action["email"]["id"]
def test_create_ignores_ids_of_existing_rows(
self,
admin_client: APIClient,
) -> None:
"""
GIVEN:
- An existing workflow
WHEN:
- A new workflow is created that carries that workflow's trigger and
action ids
THEN:
- New rows are created and the existing ones are untouched
"""
existing = make_workflow(admin_client, "existing")
response = send_json(
admin_client,
"POST",
"/api/workflows/",
workflow_body(
"new",
trigger={
"id": existing["triggers"][0]["id"],
"filter_filename": "taken",
},
action={"id": existing["actions"][0]["id"]},
),
)
assert response.status_code == status.HTTP_201_CREATED
assert response.data["triggers"][0]["id"] != existing["triggers"][0]["id"]
assert response.data["actions"][0]["id"] != existing["actions"][0]["id"]
assert WorkflowTrigger.objects.get(
pk=existing["triggers"][0]["id"],
).filter_filename != ("taken")
def test_editing_a_workflow_keeps_its_row_ids(
self,
admin_client: APIClient,
) -> None:
"""
GIVEN:
- A workflow read back from the API, as the UI does before an edit
WHEN:
- It is sent back with a changed name and email subject
THEN:
- Its trigger, action and email keep their ids and no rows are added
"""
workflow = make_workflow(admin_client, "workflow")
body = admin_client.get(f"/api/workflows/{workflow['id']}/").data
body = json.loads(json.dumps(body))
body["name"] = "renamed"
body["actions"][0]["email"]["subject"] = "edited"
response = send_json(
admin_client,
"PUT",
f"/api/workflows/{workflow['id']}/",
body,
)
assert response.status_code == status.HTTP_200_OK
assert response.data["triggers"][0]["id"] == workflow["triggers"][0]["id"]
assert response.data["actions"][0]["id"] == workflow["actions"][0]["id"]
assert (
response.data["actions"][0]["email"]["id"]
== (workflow["actions"][0]["email"]["id"])
)
assert response.data["actions"][0]["email"]["subject"] == "edited"
assert WorkflowAction.objects.count() == 1
assert WorkflowActionEmail.objects.count() == 1
assert WorkflowTrigger.objects.count() == 1
def test_a_new_action_in_an_update_is_added_beside_the_existing_one(
self,
admin_client: APIClient,
) -> None:
"""
GIVEN:
- A workflow with one action
WHEN:
- It is updated with that action plus a new one without an id
THEN:
- The first action keeps its id and a second one is created
"""
workflow = make_workflow(admin_client, "workflow")
body = json.loads(
json.dumps(admin_client.get(f"/api/workflows/{workflow['id']}/").data),
)
body["actions"].append({"type": 1, "assign_title": "added"})
response = send_json(
admin_client,
"PUT",
f"/api/workflows/{workflow['id']}/",
body,
)
assert response.status_code == status.HTTP_200_OK
assert len(response.data["actions"]) == 2
assert response.data["actions"][0]["id"] == workflow["actions"][0]["id"]
+30
View File
@@ -0,0 +1,30 @@
from pytest_mock import MockerFixture
from documents.caching import CLASSIFIER_VERSION_KEY
from documents.caching import get_suggestion_cache
from documents.caching import get_suggestion_cache_key
from documents.classifier import DocumentClassifier
class TestGetSuggestionCache:
def test_rejected_entry_is_a_cache_miss(self, mocker: MockerFixture) -> None:
"""
GIVEN:
- A document suggestion entry the cache serializer rejected, which
get_many reports as None
- A classifier version entry matching the current format
WHEN:
- The suggestion cache is read
THEN:
- It is treated as a cache miss
"""
doc_key = get_suggestion_cache_key(1)
mocker.patch(
"documents.caching.cache.get_many",
return_value={
CLASSIFIER_VERSION_KEY: DocumentClassifier.FORMAT_VERSION,
doc_key: None,
},
)
assert get_suggestion_cache(1) is None
+40
View File
@@ -0,0 +1,40 @@
import logging
from typing import Any
from paperless.signed_pickle import SignedPickleError
from paperless.signed_pickle import signed_pickle_dumps
from paperless.signed_pickle import signed_pickle_loads
logger = logging.getLogger("paperless.cache")
class SignedRedisSerializer:
"""
Cache serializer for Django's RedisCache which HMAC-signs every pickled value.
Django's default serializer unpickles whatever it finds under a key, so anything
able to write to the Redis instance could get code run in the web server, for
example through a session entry. Values are signed with SECRET_KEY on write and
verified before unpickling on read, the same protection the Celery messages on
the same broker have.
An entry that fails verification is dropped and reported as a cache miss.
"""
def dumps(self, obj: Any) -> bytes | int:
# Like Django's own serializer, keep plain integers unpickled so incr() and
# decr() stay atomic. Using type() rather than isinstance() excludes bool.
if type(obj) is int:
return obj
return signed_pickle_dumps(obj)
def loads(self, data: bytes) -> Any:
try:
return int(data)
except ValueError:
pass
try:
return signed_pickle_loads(data)
except SignedPickleError:
logger.warning("Ignoring cache entry with an invalid signature")
return None
+6
View File
@@ -807,17 +807,23 @@ _CACHE_BACKEND = os.environ.get(
) )
# Entries are HMAC-signed so values planted in Redis are never unpickled
_CACHE_OPTIONS = {"serializer": "paperless.cache.SignedRedisSerializer"}
def _parse_caches(): def _parse_caches():
return { return {
"default": { "default": {
"BACKEND": _CACHE_BACKEND, "BACKEND": _CACHE_BACKEND,
"LOCATION": _CHANNELS_REDIS_URL, "LOCATION": _CHANNELS_REDIS_URL,
"KEY_PREFIX": _REDIS_KEY_PREFIX, "KEY_PREFIX": _REDIS_KEY_PREFIX,
"OPTIONS": _CACHE_OPTIONS,
}, },
"read-cache": { "read-cache": {
"BACKEND": _CACHE_BACKEND, "BACKEND": _CACHE_BACKEND,
"LOCATION": cachalot_settings["CACHALOT_REDIS_URL"], "LOCATION": cachalot_settings["CACHALOT_REDIS_URL"],
"KEY_PREFIX": _REDIS_KEY_PREFIX, "KEY_PREFIX": _REDIS_KEY_PREFIX,
"OPTIONS": _CACHE_OPTIONS,
}, },
} }
+126
View File
@@ -0,0 +1,126 @@
import pickle
from collections.abc import Callable
from pathlib import Path
from typing import Any
import pytest
from django.conf import settings
from paperless.cache import SignedRedisSerializer
from paperless.signed_pickle import compute_signature
class _Evil:
def __init__(self, marker: Path) -> None:
self.marker = marker
def __reduce__(self) -> tuple[Any, tuple[str]]:
return (self.marker.write_text, ("pwned",))
@pytest.fixture
def serializer() -> SignedRedisSerializer:
return SignedRedisSerializer()
class TestSignedRedisSerializer:
def test_round_trip(self, serializer: SignedRedisSerializer) -> None:
"""
GIVEN:
- A nested value
WHEN:
- It is serialized and then deserialized
THEN:
- The original value is returned
"""
value = {"a": [1, 2, 3], "b": ("x", None)}
assert serializer.loads(serializer.dumps(value)) == value
@pytest.mark.parametrize(
("value", "stored_type"),
[
pytest.param(7, int, id="int"),
pytest.param(True, bytes, id="bool"),
],
)
def test_only_plain_integers_are_stored_raw(
self,
serializer: SignedRedisSerializer,
value: object,
stored_type: type,
) -> None:
"""
GIVEN:
- A plain integer or a bool
WHEN:
- The value is serialized
THEN:
- Only the integer is stored unpickled, so incr/decr stay atomic
"""
assert type(serializer.dumps(value)) is stored_type
def test_raw_integer_is_loaded(self, serializer: SignedRedisSerializer) -> None:
"""
GIVEN:
- An integer as stored by Redis incr/decr
WHEN:
- It is deserialized
THEN:
- The integer is returned without signature verification
"""
assert serializer.loads(b"7") == 7
@pytest.mark.parametrize(
"forge",
[
pytest.param(lambda data: data, id="unsigned"),
pytest.param(
lambda data: compute_signature(b"other data") + data,
id="signature-for-other-data",
),
],
)
def test_forged_pickle_is_not_loaded(
self,
serializer: SignedRedisSerializer,
tmp_path: Path,
caplog: pytest.LogCaptureFixture,
forge: Callable[[bytes], bytes],
) -> None:
"""
GIVEN:
- A malicious pickle without a valid signature
WHEN:
- It is deserialized
THEN:
- It is treated as a cache miss, never executed, and a warning is logged
"""
marker = tmp_path / "marker"
payload = forge(pickle.dumps(_Evil(marker)))
assert serializer.loads(payload) is None
assert not marker.exists()
assert "invalid signature" in caplog.text
class TestCacheSettings:
@pytest.mark.parametrize(
"alias",
[
pytest.param("default", id="default"),
pytest.param("read-cache", id="read-cache"),
],
)
def test_caches_use_signed_serializer(self, alias: str) -> None:
"""
GIVEN:
- The configured cache aliases
WHEN:
- Their options are inspected
THEN:
- Each uses the signed serializer
"""
options = settings.CACHES[alias]["OPTIONS"]
assert options["serializer"] == "paperless.cache.SignedRedisSerializer"
Generated
+506 -486
View File
File diff suppressed because it is too large. Load diff