Skip to content

PROD-10345 - Fix: Link preview fetch returns 403 for external URLs whose firewall blocks browser-like User-Agents (e.g., jeremyrhammond.com) - #5042

Open
sajib-bb wants to merge 2 commits into
releasefrom
PROD-10345
Open

PROD-10345 - Fix: Link preview fetch returns 403 for external URLs whose firewall blocks browser-like User-Agents (e.g., jeremyrhammond.com)#5042
sajib-bb wants to merge 2 commits into
releasefrom
PROD-10345

Conversation

@sajib-bb

Copy link
Copy Markdown

Jira Issue:

https://buddyboss.atlassian.net/browse/PROD-10345

General Note

Keep all conversations related to this PR in the associated Jira issue(s). Do NOT add comment on this PR or edit this PR’s description.

Notes to Developer

  • Ensure the IDs (i.e. PROD-1) of all associated Jira issues are reference in this PR’s title
  • Ensure that you have achieved the Definition of Done before submitting for review
  • When this PR is ready for review, move the associate Jira issue(s) to “Needs Review” (or “Code Review” for Dev Tasks)

Notes to Reviewer

  • Ensure that the Definition of Done have been achieved before approving a PR
  • When this PR is approved, move the associated Jira issue(s) to “Needs QA” (or “Approved” for Dev Tasks)

bp_core_parse_url() used a hardcoded browser-style User-Agent for its
server-side fetch. Some external sites run a firewall/WAF that blocks
that signature while allow-listing known link-preview bots
(facebookexternalhit, Twitterbot, Slackbot), so the preview request
was rejected with a 403.

- Add a bp_core_parse_url_http_args filter around both fetch call
  sites so the User-Agent (or any other request arg) can be
  overridden per-site.
- Stop treating non-2xx responses as a successful fetch: a WAF block
  page's own HTML (e.g. containing a literal "403 Forbidden" title)
  was being scraped and cached as a real preview for 24 hours.
The link preview fetch previously always used a browser-style
User-Agent, which some external sites' firewalls block while still
allow-listing known link-preview bots (facebookexternalhit,
Twitterbot, Slackbot).

- bp_core_parse_url() now tries facebookexternalhit/1.1 first via
  bp_core_get_link_preview_user_agent() (filterable via
  bp_core_parse_url_user_agent).
- If that request doesn't return a usable title/description/image,
  it automatically retries with the previous browser User-Agent via
  bp_core_get_link_preview_fallback_user_agent() (filterable via
  bp_core_parse_url_fallback_user_agent). This keeps working, with no
  custom code required, for sites that only serve full preview markup
  to browser-style requests.
- Extracted the OG/meta-tag scraping logic into
  bp_core_extract_link_preview_data_from_html() so it can be reused
  for each User-Agent attempt without duplicating the parsing code.
@sajib-bb
sajib-bb requested a review from reza-bb August 24, 2026 12:58
@sajib-bb sajib-bb self-assigned this Aug 24, 2026
@sajib-bb
sajib-bb removed the request for review from reza-bb August 24, 2026 14:52
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.

1 participant