Skip to content

Conversation

@adamsaimi
Copy link
Owner

Test 4

return if user.blank?

require 'simple-rss'
rss = SimpleRSS.parse open(SiteSetting.feed_polling_url)
Copy link
Owner Author

Choose a reason for hiding this comment

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

[Security] Server-Side Request Forgery (SSRF) in poll_feed

  • Problem: The open(SiteSetting.feed_polling_url) call lacks URL validation, making it vulnerable to SSRF if the URL is attacker-controlled.
  • Fix: Implement strict URL validation (whitelist schemes, restrict public IP ranges, prevent internal network access) before calling open.

def cook(*args)
# For some posts, for example those imported via RSS, we support raw HTML. In that
# case we can skip the rendering pipeline.
return raw if cook_method == Post.cook_methods[:raw_html]
Copy link
Owner Author

Choose a reason for hiding this comment

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

[Security] Cross-Site Scripting (XSS) via raw_html cook method

  • Problem: The raw_html cook method bypasses sanitization, allowing malicious HTML/JavaScript from imported content to be rendered directly, leading to XSS.
  • Fix: Apply robust HTML sanitization (e.g., Sanitize gem) to all external contents before saving and rendering, even when cook_method is raw_html.

require 'ruby-readability'

opts = opts || {}
doc = Readability::Document.new(open(url).read,
Copy link
Owner Author

Choose a reason for hiding this comment

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

[Security] Server-Side Request Forgery (SSRF) in import_remote

  • Problem: The open(url).read call in import_remote lacks URL validation, making it vulnerable to SSRF if url is attacker-controlled.
  • Fix: Implement strict URL validation (whitelist schemes, restrict public IP ranges, prevent internal network access) before calling open.

<img src='<%= post.user.small_avatar_url %>'>
<h3><%= post.user.username %></h3>
</div>
<div class='cooked'><%= raw post.cooked %></div>
Copy link
Owner Author

Choose a reason for hiding this comment

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

[Security] Cross-Site Scripting (XSS) via raw post.cooked rendering

  • Problem: Directly rendering raw post.cooked from untrusted external sources allows malicious HTML/JavaScript to execute, leading to XSS.
  • Fix: Ensure all raw_html content is thoroughly sanitized against XSS before storage or rendering, or apply a strict sanitization filter at the rendering stage.


function postMessageReceived(e) {
if (!e) { return; }
if (discourseUrl.indexOf(e.origin) === -1) { return; }
Copy link
Owner Author

Choose a reason for hiding this comment

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

[Security] Weak postMessage Origin Validation

  • Problem: The indexOf check for e.origin is insufficient, allowing attackers to bypass validation with crafted domains and receive sensitive postMessage data.
  • Fix: Implement robust origin validation using exact equality (e.origin === discourseUrl) or by parsing and comparing URL.host properties.

validates_presence_of :content_sha1

# Import an article from a source (RSS/Atom/Other)
def self.import(user, url, title, contents)
Copy link
Owner Author

Choose a reason for hiding this comment

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

[Architecture] Service Logic in TopicEmbed Model

  • Problem: TopicEmbed.import and TopicEmbed.import_remote contain extensive business logic, violating the Single Responsibility Principle and making the model bloated and less maintainable.
  • Fix: Extract complex service-like logic (content fetching, parsing, orchestration) into dedicated service objects or modules.

window.onload = function() {
if (parent) {
// Send a post message with our loaded height
parent.postMessage({type: 'discourse-resize', height: document['body'].offsetHeight}, '<%= request.referer %>');
Copy link
Owner Author

Choose a reason for hiding this comment

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

[Security] Weak postMessage Target Origin

  • Problem: Using request.referer as targetOrigin for postMessage is insecure, as Referer can be spoofed, leading to information leakage to malicious origins.
  • Fix: Set targetOrigin to a fixed, known, and trusted origin (e.g., SiteSetting.embeddable_host) instead of relying on request.referer.

end

def cook(*args)
# For some posts, for example those imported via RSS, we support raw HTML. In that
Copy link
Owner Author

Choose a reason for hiding this comment

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

[Architecture] Divergent Post Processing Pipeline for raw_html

  • Problem: raw_html posts bypass the standard Plugin::Filter.apply(:after_post_cook) step, creating inconsistencies and potential missed plugin functionality.
  • Fix: Re-evaluate the raw_html cook method to ensure it integrates with or explicitly handles the standard post-cooking pipeline, or document the divergence clearly.


# First check RSS if that is enabled
if SiteSetting.feed_polling_enabled?
Jobs::PollFeed.new.execute({})
Copy link
Owner Author

Choose a reason for hiding this comment

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

[Architecture] Synchronous Job Execution in TopicRetriever

  • Problem: TopicRetriever directly calls Jobs::PollFeed.new.execute({}), bypassing the asynchronous job queue and potentially blocking the retriever.
  • Fix: Enqueue Jobs::PollFeed properly for background execution to leverage asynchronous processing and avoid blocking TopicRetriever.

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.

3 participants