8000 Improve URL validation security and CloudFlare compatibility by mikeydorje · Pull Request #22406 · forem/forem · GitHub
[go: up one dir, main page]

Skip to content

Conversation

mikeydorje
Copy link
Contributor

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

Related Tickets & Documents

  • Related Issue #
  • Closes #

QA Instructions, Screenshots, Recordings

Please replace this line with instructions on how to test your changes, a note
on the devices and browsers this has been tested on, as well as any relevant
images for UI changes.

UI accessibility checklist

If your PR includes UI changes, please utilize this checklist:

  • Semantic HTML implemented?
  • Keyboard operability supported?
  • Checked with axe DevTools and addressed Critical and Serious issues?
  • Color contrast tested?

For more info, check out the
Forem Accessibility Docs.

Added/updated tests?

We encourage you to keep the code coverage percentage at 80% and above.

  • Yes
  • No, and this is why: please replace this line with details on why tests
    have not been included
  • I need help with writing tests

[optional] Are there any post deployment tasks we need to perform?

[optional] What gif best describes this PR or how it makes you feel?

alt_text

Copy link
Contributor
github-actions bot commented Oct 3, 2025

Thank you for opening this PR! We appreciate you!

For all pull requests coming from third-party forks we will need to
review the PR before we can process it through our CI pipelines.

A Forem Team member will review this contribution and get back to
you as soon as possible!

- Fix CloudFlare Bot Fight Mode issues by improving User-Agent format
- Add SSRF protection to prevent requests to private/internal IPs
- Add HTTP timeout settings to prevent hanging requests
- Fix status post URL processing to match production behavior
- Extract URLs from status post titles automatically

Changes:
- UnifiedEmbed::Tag: Better User-Agent, SSRF protection, timeouts
- Article: Auto-extract URLs from status post titles for processing
@mikeydorje mikeydorje force-pushed the mikeydorje/improve-url-validation-security branch from abe9d92 to 43547ef Compare October 3, 2025 21:17
…verage

Security Improvements:
- Enhanced DNS resolution in private_ip? method using Addrinfo.getaddrinfo()
- Improved error handling for hostname resolution failures
- Maintained CloudFlare Bot Fight Mode compatibility
- Added proper HTTP timeouts (10s open, 15s read)
- CloudFlare-friendly User-Agent format (ForemLinkValidator/1.0)

Test Coverage:
- Added 144 lines of comprehensive RSpec tests for SSRF protection
- Added 48 lines of tests for Article URL extraction functionality
- Tests cover private IP detection, DNS resolution scenarios, timeout verification
- Validates User-Agent format and bypass logic for trusted domains

Features:
- Robust protection against SSRF attacks while maintaining embed functionality
- Enhanced status post URL extraction with punctuation handling
- Comprehensive test suite ensuring security and functionality work together
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
0