Skip to content

Enhance embed URL handling and validation system#7

Open
akshayutture-augment wants to merge 1 commit into
embed-url-handling-prefrom
embed-url-handling-post
Open

Enhance embed URL handling and validation system#7
akshayutture-augment wants to merge 1 commit into
embed-url-handling-prefrom
embed-url-handling-post

Conversation

@akshayutture-augment

@akshayutture-augment akshayutture-augment commented Nov 14, 2025

Copy link
Copy Markdown

Test 4


Replicated from ai-code-review-evaluation/discourse-cursor#4


Note

Introduces an embeddable comments iframe and a backend pipeline to import external articles/RSS into topics using Readability, with new model/jobs, routes, settings, and raw_html cooking.

  • Embedding UI:
    • Adds embed.js, embed.css.scss, and views/layout to render best replies in an iframe and auto-resize.
    • New route GET /embed/best and EmbedController#best with referer/host checks.
  • Content Import Pipeline:
    • New TopicEmbed model for linking external embed_url to topics; imports content (absolutizes URLs) and updates on change.
    • TopicRetriever service and Jobs::RetrieveTopic to fetch/import on demand; scheduled Jobs::PollFeed to parse RSS/Atom via SimpleRSS.
    • Disqus import task now uses TopicEmbed.import_remote.
  • Post rendering:
    • Adds Post.cook_methods and raw_html support; skips pipeline when set.
    • Wire-through in PostCreator and validation control in PostRevisor.
  • Data model & migrations:
    • Create topic_embeds table; add posts.cook_method (default), adjust top_topics creation options.
  • Settings & locales:
    • New site settings under embedding (embeddable_host, feed_polling_enabled, feed_polling_url, embed_by_username) and client category.
    • New server/client i18n for embed UI strings.
  • Dependencies:
    • Adds ruby-readability and simple-rss gems (and lockfile updates).
  • Specs:
    • Tests for TopicRetriever, EmbedController, PollFeed, and TopicEmbed behavior.

Written by Cursor Bugbot for commit 4f8aed2. Configure here.

@akshayutture-augment

Copy link
Copy Markdown
Author

cursor review


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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Origin Validation Flaw: Domain Spoofing Risk

The origin validation uses indexOf which allows substring matches, enabling messages from malicious domains. For example, if discourseUrl is "http://discourse.example.com", a message from "example.com" would pass validation since indexOf returns a non-negative value. The check needs to verify exact origin matching rather than substring presence.

Fix in Cursor Fix in Web

Comment thread app/models/topic_embed.rb
def self.import(user, url, title, contents)
return unless url =~ /^https?\:\/\//

contents << "\n<hr>\n<small>#{I18n.t('embed.imported_from', link: "<a href='#{url}'>#{url}</a>")}</small>\n"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Dangerous URLs: Code Injection Vulnerability

The url parameter is directly interpolated into HTML without escaping, creating an XSS vulnerability. A malicious URL containing characters like <script> or " could break out of the HTML context and execute arbitrary JavaScript when the embedded content is rendered.

Fix in Cursor Fix in Web

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
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Referer Header: A Gateway to XSS

The request.referer value is directly interpolated into JavaScript without escaping, creating an XSS vulnerability. A malicious referer header containing a single quote could break out of the string literal and execute arbitrary JavaScript in the parent window context.

Fix in Cursor Fix in Web

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.

2 participants