Skip to content

Fix /follows.json POST handler to validate publisher exists before database write#11149

Draft
mekarpeles with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-11112
Draft

Fix /follows.json POST handler to validate publisher exists before database write#11149
mekarpeles with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-11112

Conversation

Copilot AI commented Aug 14, 2025

Copy link
Copy Markdown
Contributor

The /follows.json POST handler was allowing authenticated users to follow any publisher username without validating that the publisher account actually exists. This could lead to invalid follow relationships being written to the database.

Changes Made

Added publisher validation to the patrons_follows_json.POST() method in openlibrary/plugins/openlibrary/api.py:

# Validate that the publisher account exists
publisher_account = accounts.find(username=i.publisher)
if not publisher_account:
    raise web.notfound("Publisher not found")

The validation occurs after user authentication but before the database write operation. If the publisher account doesn't exist, the handler now returns a proper 404 error instead of proceeding with the follow/unfollow action.

Testing

Added comprehensive test coverage in openlibrary/plugins/openlibrary/tests/test_followsapi.py to verify:

  • Attempting to follow a non-existent publisher returns 404
  • Existing functionality remains unaffected

All existing tests continue to pass, confirming no regression in functionality.

Security Impact

This fix prevents the creation of follow relationships with non-existent users, improving data integrity and preventing potential issues from invalid publisher references in the follows table.

Fixes #11112.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…iting to DB

Co-authored-by: mekarpeles <978325+mekarpeles@users.noreply.github.com>
Copilot AI changed the title [WIP] /follows.json POST handler does not validate publisher Fix /follows.json POST handler to validate publisher exists before database write Aug 14, 2025
Copilot AI requested a review from mekarpeles August 14, 2025 22:57
@jimchamp

jimchamp commented Aug 23, 2025

Copy link
Copy Markdown
Collaborator

If these are opened as drafts, our reviewer assignment script will ignore them.

@mekarpeles

Copy link
Copy Markdown
Member

Hi @copilot-swe-agent — this fix (validating publisher exists before writing to the follows table) was already incorporated into the master branch. You can see the current implementation at line 377–379 of openlibrary/plugins/openlibrary/api.py on master, which includes:

publisher_account = accounts.find(username=i.publisher)
if not publisher_account:
    raise web.notfound()

Master also already has the accompanying test in test_followsapi.py. This PR can be closed as the changes are already merged.

Copilot AI commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

Hi @copilot-swe-agent — this fix (validating publisher exists before writing to the follows table) was already incorporated into the master branch. You can see the current implementation at line 3...

Thanks for the heads-up! Since the publisher validation fix is already in master (lines 377–379 of openlibrary/plugins/openlibrary/api.py) along with the accompanying tests, this PR is indeed redundant. Feel free to close it.

@github-actions github-actions Bot added the Needs: Response Issues which require feedback from lead label May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs: Response Issues which require feedback from lead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/follows.json POST handler does not validate publisher

3 participants