Skip to content

fix: close small pre-release review gaps - #522

Merged
uniqueg merged 4 commits into
devfrom
fix/v018-low-findings
Oct 26, 2026
Merged

uniqueg merged 4 commits into
devfrom
fix/v018-low-findings

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Summary

Small findings of the v0.18.0 pre-release review:

  • SSRF guard: is_public_address() (and thus GuardedClient) now rejects IPv6 site-local addresses (fec0::/10), which ipaddress.is_global reports as globally reachable. Regression test added; docs/utilities.md updated.
  • Base image build context: the root .dockerignore is now an allowlist of the files docker/Dockerfile copies (pyproject.toml, MANIFEST.in, README.md, LICENSE, foca/), and excludes .env* (except .env.example), __pycache__ and bytecode inside them, so local files can't end up in the published base image. The Dockerfile points to the allowlist.
  • petstore-access-control README: recommends the permissions API (or group mappings for the first admin) instead of editing rules in the database directly, and says that direct edits need a restart (since perf(access-control): cache the policy enforcer #454).

Closes #516

Verification

  • pytest tests/utils/test_http.py: the new case fec0::1 failed before the fix, 70 passed after.
  • Full suite (coverage run -m pytest -m "not mongodb"): 2789 passed, 1 skipped, 100% coverage. MongoDB-marked tests not run locally (no mongod); the change doesn't touch them, CI runs them.
  • ruff check, ruff format --check, mypy, ast-grep scan, semgrep scan --config .semgrep --error, mkdocs build --strict: all pass.
  • .dockerignore: no Docker daemon available locally. Checked with an emulation of Docker's matching rules (allowlisted files included; foca/.env, foca/**/.env.local, __pycache__, .git, docs/, tests/ excluded; foca/.env.example included), and built a wheel from only the allowlisted files (uv build --wheel, OK). The CI image builds verify it for real.
  • CI: all checks passed, including the image builds from the root context (Integration test, Scan image for Python 3.11-3.15).
  • Reviewer subagents (adversarial, quality): no high or medium findings; the one low (point the Dockerfile to the allowlist) is fixed.

Declined review findings

  • Quality, low: the __pycache__/bytecode patterns duplicate MANIFEST.in's global-exclude. Kept: the build context is a separate boundary from the sdist, and the reviewer also suggested keeping them.

🤖 Generated with Claude Code

Summary by Sourcery

Close pre-release security, container build-context, and access-control documentation gaps.

Bug Fixes:

  • Reject IPv6 site-local addresses in public-address checks to prevent SSRF bypasses.

Build:

  • Restrict the Docker build context to an explicit allowlist and exclude environment files, caches, bytecode, and unrelated repository content.

Documentation:

  • Clarify public-address behavior and update the petstore access-control guidance for permissions API usage, initial admin setup, and restart requirements for direct database changes.

Tests:

  • Add regression coverage for IPv6 site-local address rejection.

uniqueg and others added 4 commits October 26, 2026 17:21
ipaddress.is_global is True for the deprecated site-local range
fec0::/10, so the SSRF guard of GuardedClient treated such addresses
as public. Reject them explicitly.

Part of #516

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The root .dockerignore excluded only examples/, so local files such as
foca/.env or __pycache__ directories went into the published base
image. Allow only the files docker/Dockerfile copies, and exclude
.env files (except .env.example) and bytecode inside them.

Part of #516

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since #454, running apps ignore rules changed in the database directly
until they restart. Recommend the permissions API (or group mappings for
the first admin) in the petstore-access-control example, and say that
direct database edits need a restart.

Part of #516

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Files copied by docker/Dockerfile must also be allowed in .dockerignore.

Part of #516

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg uniqueg added this to the v0.18.0 milestone Oct 26, 2026
@sourcery-ai

sourcery-ai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Closes pre-release review gaps by hardening IPv6 SSRF checks, isolating Docker builds from unintended local files with an allowlisted context, and correcting petstore access-control administration guidance.

Sequence diagram for guarded public-address validation

sequenceDiagram
    participant GuardedClient
    participant is_public_address
    participant ipaddress

    GuardedClient->>is_public_address: is_public_address(address)
    is_public_address->>ipaddress: address.is_site_local
    alt IPv6 site-local address
        is_public_address-->>GuardedClient: False
    else Other address
        is_public_address->>ipaddress: address.is_global
        is_public_address-->>GuardedClient: is_global and not multicast
    end
Loading

File-Level Changes

Change Details Files
Extend SSRF protection to reject deprecated IPv6 site-local addresses.
  • Check IPv6Address.is_site_local before the global-address result.
  • Add regression coverage for fec0::1 through GuardedClient.
  • Document the additional address rejection rule.
foca/utils/http.py
tests/utils/test_http.py
docs/utilities.md
Restrict the Docker build context to an explicit, sanitized source allowlist.
  • Allow only the Dockerfile inputs needed to build the base image.
  • Exclude environment files, generated bytecode, caches, repository metadata, documentation, and tests while retaining .env.example.
  • Document that Dockerfile COPY sources must remain in the allowlist.
.dockerignore
docker/Dockerfile
Clarify the supported workflow for configuring petstore administrators and policy changes.
  • Recommend the permissions API for ongoing admin and policy updates.
  • Describe group mappings or a database rule plus restart for bootstrapping the first administrator.
  • Explain that direct database edits are not observed by running applications.
examples/petstore-access-control/README.md

Assessment against linked issues

Issue Objective Addressed Explanation
#516 Reject IPv6 site-local addresses in the SSRF public-address check and add regression coverage. ✅
#516 Restrict the Docker build context to the files needed for the base image, while excluding sensitive environment files and Python cache/bytecode files from allowed paths. ✅
#516 Update the petstore-access-control README to recommend the permissions API for rule changes and clarify that direct database edits require an app restart. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Oct 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (58f8e55) to head (08e9240).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #522   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           55        55           
  Lines         6609      6611    +2     
=========================================
+ Hits          6609      6611    +2     
Flag Coverage Δ
test_unit 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review October 26, 2026 17:48

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@uniqueg
uniqueg merged commit 23825a2 into dev Oct 26, 2026
30 checks passed
@uniqueg
uniqueg deleted the fix/v018-low-findings branch October 26, 2026 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: close small pre-release review gaps

1 participant