Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

allow file-only messages with no text to be sent in chat panel and deployed chat

Type of Change

  • Bug fix

Testing

Tested manually by sending messages with no text and only images.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Oct 15, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Oct 15, 2025 3:26am

@waleedlatif1 waleedlatif1 merged commit 7595e54 into staging Oct 15, 2025
4 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/chat branch October 15, 2025 03:27
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Overview

Summary

Enables sending messages with file attachments only (no text required) in both chat panel and deployed chat by conditionally rendering the message text bubble.

Key Changes:

  • Conditionally renders message bubble only when text content exists and doesn't start with "Sent"/"Uploaded"
  • Adds enhanced image attachment preview that opens in a new window with custom HTML
  • Adds validation to check dataUrl.startsWith('data:') before rendering images or enabling click handlers
  • Fixes missing useCallback dependencies in chat.tsx (chatFiles, isUploadingFiles, setter functions)

Critical Issues Found:

  • XSS vulnerabilities: attachment.name is directly interpolated into HTML (document.write) without escaping in 4 locations across 2 files. A malicious filename like </title><script>alert('XSS')</script> will execute JavaScript.

Confidence Score: 1/5

  • This PR contains critical XSS vulnerabilities that must be fixed before merging
  • Score reflects 4 XSS vulnerabilities where user-controlled filenames are injected into HTML without escaping. While the dependency array fix is correct, the security issues make this unsafe to merge.
  • Pay close attention to apps/sim/app/chat/components/message/message.tsx and apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/chat/components/chat-message/chat-message.tsx - both contain XSS vulnerabilities

Important Files Changed

File Analysis

Filename Score Overview
apps/sim/app/chat/components/message/message.tsx 1/5 Allows file-only messages by conditionally rendering text bubble; adds image preview in new window with XSS vulnerabilities in attachment.name handling
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/chat/chat.tsx 4/5 Added missing dependencies (chatFiles, isUploadingFiles, setChatMessage, setChatFiles, setUploadErrors) to handleSendMessage useCallback
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/chat/components/chat-message/chat-message.tsx 1/5 Allows file-only messages by conditionally rendering text bubble; adds image preview in new window with XSS vulnerabilities in attachment.name handling

Sequence Diagram

sequenceDiagram
    participant User
    participant ChatInput
    participant ChatComponent
    participant MessageComponent
    participant Browser
    
    User->>ChatInput: Upload file + optional text
    ChatInput->>ChatComponent: handleSendMessage()
    
    alt Has text content
        ChatComponent->>MessageComponent: Render attachments + text bubble
    else File-only (no text)
        ChatComponent->>MessageComponent: Render attachments only (skip text bubble)
    end
    
    User->>MessageComponent: Click attachment
    MessageComponent->>MessageComponent: Check dataUrl.startsWith('data:')
    MessageComponent->>Browser: window.open('', '_blank')
    MessageComponent->>Browser: document.write(HTML with attachment.name)
    Browser->>User: Display attachment in new window
Loading

3 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

<!DOCTYPE html>
<html>
<head>
<title>${attachment.name}</title>
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: XSS vulnerability: ${attachment.name} is not HTML-escaped. If a user uploads a file named &lt;/title&gt;&lt;script&gt;alert('XSS')&lt;/script&gt;, it will execute JavaScript in the new window.

Suggested change
<title>${attachment.name}</title>
<title>${attachment.name.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;')}</title>
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/app/chat/components/message/message.tsx
Line: 105:105

Comment:
**logic:** XSS vulnerability: `${attachment.name}` is not HTML-escaped. If a user uploads a file named `&lt;/title&gt;&lt;script&gt;alert('XSS')&lt;/script&gt;`, it will execute JavaScript in the new window.

```suggestion
                                    <title>${attachment.name.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;')}</title>
```

How can I resolve this? If you propose a fix, please make it concise.

</style>
</head>
<body>
<img src="${validDataUrl}" alt="${attachment.name}" />
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: XSS vulnerability: ${attachment.name} in the alt attribute is not HTML-escaped.

Suggested change
<img src="${validDataUrl}" alt="${attachment.name}" />
<img src="${validDataUrl}" alt="${attachment.name.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;')}" />
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/app/chat/components/message/message.tsx
Line: 112:112

Comment:
**logic:** XSS vulnerability: `${attachment.name}` in the alt attribute is not HTML-escaped.

```suggestion
                                    <img src="${validDataUrl}" alt="${attachment.name.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;')}" />
```

How can I resolve this? If you propose a fix, please make it concise.

<!DOCTYPE html>
<html>
<head>
<title>${attachment.name}</title>
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: XSS vulnerability: ${attachment.name} is not HTML-escaped.

Suggested change
<title>${attachment.name}</title>
<title>${attachment.name.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;')}</title>
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/chat/components/chat-message/chat-message.tsx
Line: 113:113

Comment:
**logic:** XSS vulnerability: `${attachment.name}` is not HTML-escaped.

```suggestion
                                <title>${attachment.name.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;')}</title>
```

How can I resolve this? If you propose a fix, please make it concise.

</style>
</head>
<body>
<img src="${validDataUrl}" alt="${attachment.name}" />
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: XSS vulnerability: ${attachment.name} in the alt attribute is not HTML-escaped.

Suggested change
<img src="${validDataUrl}" alt="${attachment.name}" />
<img src="${validDataUrl}" alt="${attachment.name.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;')}" />
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/chat/components/chat-message/chat-message.tsx
Line: 120:120

Comment:
**logic:** XSS vulnerability: `${attachment.name}` in the alt attribute is not HTML-escaped.

```suggestion
                                <img src="${validDataUrl}" alt="${attachment.name.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;')}" />
```

How can I resolve this? If you propose a fix, please make it concise.

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