Skip to content

Conversation

humitos
Copy link
Member

@humitos humitos commented Jul 16, 2025

Screenshot_2025-07-16_16-42-23

Closes #82

@humitos humitos requested a review from a team as a code owner July 16, 2025 14:42
@humitos humitos requested a review from agjohnson July 16, 2025 14:43
humitos added a commit that referenced this pull request Jul 16, 2025
This example was missing.

On top of #634
</div>
<code data-bind="text: redirect_to"></code>
<div class="sub header">{% trans "Redirect to" %}</div>
<code data-bind="html: redirect_to"></code>
Copy link
Member

Choose a reason for hiding this comment

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

This is likely vulnerable to XSS, we are dealing with user input here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can we mark the user input as unsafe somehow while keeping the current pattern? I mean, calling something like unsafe(user_input) so all the HTML tags are converted to regular safe strings.

Copy link
Member

Choose a reason for hiding this comment

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

Don't think knockout has a feature like that. This is probably better as a web component, so you don't need to build the HTML manually.

Copy link
Member Author

Choose a reason for hiding this comment

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

I used DOMPurify.sanitize() which is the same we are already using for the notifications.

Copy link
Member

Choose a reason for hiding this comment

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

What you need here is to escape the text, not sanitize it.

Copy link
Member

Choose a reason for hiding this comment

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

Injecting HTML is still dangerous, it can be used to leak information from the page, steal credentials, etc. DOMPurify is being used as an additional layer for notifications, but all values are escaped in notifications.

Copy link
Member Author

Choose a reason for hiding this comment

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

DOMPurify sanitizes HTML and prevents XSS attacks. You can feed DOMPurify with string full of dirty HTML and it will return a string (unless configured otherwise) with clean HTML. DOMPurify will strip out everything that contains dangerous HTML and thereby prevent XSS attacks and other nastiness.

(this is from the https://github.com/cure53/DOMPurify)


Whom are we protecting against? If the user adds HTML to the to_/from_ fields they are the only ones that are going to "evaluate" that HTML code --so, they will be "stealing" themselves. In any case, DOMPurify will prevent this to happen by making the HTML written to be clean.

Copy link
Member

Choose a reason for hiding this comment

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

Again, this isn't just about being able to execute JS, it's about never allowing users to include arbitrary HTML in the dashboard. Injecting HMLT without executing JS is still a security risk that allows exfiltrating information. This page is shared across maintainers, so this isn't a self-injection vuln, but even there, we should never allow users to inject HTML into our pages.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the approach here could be easily tweaked slightly. It is a bit janky you can input HTML into the field and it renders:

image

It's not necessary to sanitize the user input if we just treat it as text instead of HTML, so splitting up our HTML and the user input text would solve this.

Ideally, I wanted this to be a web component so that the same display could be used in the listing view as well. That can be a next step, though I had a POC kicking around in my stash for this too.

Copy link
Contributor

Choose a reason for hiding this comment

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

I pushed up a commit that just splits the field up into a prefix and the user content. It's not a great pattern, we should probably just replace this all with a web component that renders everything consistently.


this.redirect_from = ko.computed(() => {
var from_url = this.from_url();
var from_url = DOMPurify.sanitize(this.from_url());
Copy link
Contributor

Choose a reason for hiding this comment

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

Note, const here should be used instead of var, the value is immutable.

@agjohnson agjohnson requested a review from stsewd August 9, 2025 00:02
@humitos
Copy link
Member Author

humitos commented Aug 11, 2025

Cool! Are we ready to merge this PR?

@agjohnson
Copy link
Contributor

#633 is conflicting with this and could just be brought in here too, I've got a little energy today I'll attempt that update here as well.

@agjohnson
Copy link
Contributor

Actually, that seemed to already be added to the logic here too. This could use a look over still but should be safe otherwise.

@agjohnson agjohnson merged commit f88fd3e into humitos/new-redirect-type Aug 13, 2025
4 checks passed
@agjohnson agjohnson deleted the humitos/redirect-syntax-highlight branch August 13, 2025 00:47
@stsewd stsewd mentioned this pull request Aug 20, 2025
agjohnson added a commit that referenced this pull request Aug 20, 2025
<img width="607" height="320" alt="Screenshot_2025-07-16_16-42-23"
src="https://github.com/user-attachments/assets/3eb38c81-6c88-4772-a234-39dc62e55252"
/>


Closes #82

---------

Co-authored-by: Anthony Johnson <[email protected]>
agjohnson added a commit that referenced this pull request Aug 20, 2025
Rebased on main. Build assets are up to date.

- Fixes #645

---------

Co-authored-by: Manuel Kaufmann <[email protected]>
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