PubSub.get_feed()` exposes reading log entries from patrons who have set their log to private
Problem
get_feed() fetches all bookshelves_books rows for followed users without checking
whether each publisher has a public reading log:
subscriptions = cls.get_following(subscriber, exclude_disabled=True)
usernames = [sub['publisher'] for sub in subscriptions]
# ...
query = (
"SELECT * FROM bookshelves_books WHERE username IN $usernames"
" ORDER BY created DESC LIMIT $limit OFFSET $offset"
)
exclude_disabled=True only filters rows where the follow relationship is disabled
(i.e. the subscriber toggled privacy on their own follows). It does not check whether
the publisher's reading log is public.
The privacy flag lives on the user's preferences as public_readlog: yes/no.
patrons_who_also_read() in bookshelves.py correctly checks this:
if p.dict().get('notifications', {}).get('public_readlog') == 'yes'
But get_feed() never does this check, so a patron who sets their reading log to private
still has their activity visible in every follower's feed.
Reproducing the bug
- Go to File:
openlibrary/core/follows.py - Go to Function get_feed(cls, subscriber, limit=25, offset=0)
-
Expected behavior: When a patron sets their reading log to private, their shelving activity (books added to want-to-read, currently-reading, already-read) should not appear in any follower's feed. The feed should only surface activity from patrons who have explicitly set their reading log to public.
-
Actual behavior: A patron's shelving activity appears in all their followers' feeds regardless of their reading log privacy setting. PubSub.get_feed() queries bookshelves_books for all followed users without checking the public_readlog preference, so setting a reading log to private has no effect on feed visibility.
Context
- Browser (Chrome, Safari, Firefox, etc):
- OS (Windows, Mac, etc):
- Logged in (Y/N):
- Environment (prod, dev, local): prod
Breakdown
No response
Hi @michelleallen122 , I would like to work on this issue.
From my understanding, the problem is that get_feed() does not check whether a followed user has their public_readlog set to 'yes', causing private reading activity to appear in followers’ feeds.
My approach would be:
- Fetch user preferences in batch using
web.ctx.site.get_many() - Filter the list of usernames to include only those with
public_readlog == 'yes'(similar to logic inbookshelves.py) - Use the filtered list in the existing query so that private logs are never fetched
This ensures both correctness and avoids unnecessary database queries.
Please let me know if this approach looks good, and I can proceed with the implementation.
Note: This is my first time trying to contribute in opensource :D
Thanks @Arnav-0206, i also have a fix for this. i'm waiting for the maintainers to comment on this before i link a pr.
i would love to be assigned this issue
@michelleallen122 thank you for identifying this opportunity. It seems like this deserves attention; assigning you and making @jimchamp the lead
This is not an issue. Only publishers who have public reading log visibility settings will be included in the results returned by PubSub.get_feed(). The filtering happens here:
https://github.com/internetarchive/openlibrary/blob/0cd1ee934506d627254b517481f14e7f0a1e8c4e/openlibrary/core/follows.py#L89
The disabled flag in the follows table is toggled whenever a publisher toggles their account privacy setting.