Skip to content

fix(tools): validate Tool Icon Source URL and default icon fallbacks (#6369)#6376

Open
ExileK1G wants to merge 1 commit into
FlowiseAI:mainfrom
ExileK1G:fix/issue-6369-tool-icon-validation
Open

fix(tools): validate Tool Icon Source URL and default icon fallbacks (#6369)#6376
ExileK1G wants to merge 1 commit into
FlowiseAI:mainfrom
ExileK1G:fix/issue-6369-tool-icon-validation

Conversation

@ExileK1G
Copy link
Copy Markdown

Fixes #6369

Summary

  • Tool Icon Source is optional; when non-empty it must be a valid http or https URL (client + server).
  • UI: validation in the tool dialog, disabled save when invalid, extra guard before API calls; safe handling when iconSrc is null from API.
  • Lists: card and table views resolve displayable icon URLs; invalid strings fall back to gradient / default asset in the tools table.
  • Robustness: formatDataGridRows returns [] when parsed schema is not an array.

How to test

  1. pnpm build (or at least pnpm --filter flowise-ui build) then pnpm start.
  2. Tools → Create: leave icon empty → save → list shows fallback; open edit → no blank page.
  3. Invalid icon (e.g. abc123) → error + cannot save.
  4. Valid https://… icon → saves and displays.

Notes

  • pnpm lint reports 0 errors; existing warnings in unrelated test files remain unchanged.

)

- Require http(s) URLs when set; optional empty with server-side normalization
- Tool dialog validation, save guards, and iconSrc null safe state
- Item card / tools table fallbacks for invalid or missing icon URLs
- formatDataGridRows: guard non-array parsed schema

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces server and client-side validation for tool icon URLs, ensuring they use valid http/https protocols. Key updates include new normalization utilities, enhanced icon rendering with fallbacks in UI components, improved error handling in the ToolDialog, and defensive array checks in the data grid helper. Feedback highlights a discrepancy between UI validation and rendering support for relative or data URLs, suggests more defensive string handling in the UI, and notes the strict enforcement of absolute URLs in the backend.

const trimmed = iconSrc.trim()
if (!trimmed) return null
try {
const u = new URL(trimmed)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

In Node.js, new URL(trimmed) will throw a TypeError if the input is not an absolute URL (e.g., just a domain like example.com). While the catch block correctly handles this by throwing a BAD_REQUEST error, it's worth noting that this implementation strictly enforces absolute URLs. This is consistent with the goal of validating the icon source and promotes fail-fast behavior for invalid external data types.

References
  1. When handling potentially invalid data from external sources (like an API response), prefer throwing an error for invalid input types rather than silently returning a default or empty value. This promotes fail-fast behavior.

Comment on lines +41 to +50
export function getItemCardIconBackgroundUrl(iconSrc) {
if (iconSrc == null) return null
const t = String(iconSrc).trim()
if (!t) return null
const http = getValidHttpOrHttpsToolIconUrl(t)
if (http) return http
if (t.startsWith('/') || t.startsWith('./')) return t
if (t.toLowerCase().startsWith('data:')) return t
return null
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

There is a slight discrepancy between the UI rendering logic and the validation logic. getItemCardIconBackgroundUrl allows relative paths (/, ./) and data: URLs for display, but the validation in ToolDialog.jsx strictly requires http or https. To ensure a safe fallback mechanism, the validation logic should be updated to match the supported rendering formats, ensuring that validly rendered icons can also be saved.

References
  1. When using a heuristic for detection (e.g., for content type), ensure a safe fallback mechanism is in place to correctly handle cases where the heuristic fails.

Comment thread packages/ui/src/views/tools/ToolDialog.jsx
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.

BugFix : Add Validation check for TOOL ICON SOURCE Field in Tools Dialogue, and add a default icon image if user has not provided

1 participant