Skip to content

Validate filepaths in file utilities#5778

Closed
christopherholland-workday wants to merge 34 commits intomainfrom
path-expression
Closed

Validate filepaths in file utilities#5778
christopherholland-workday wants to merge 34 commits intomainfrom
path-expression

Conversation

@christopherholland-workday
Copy link
Contributor

@christopherholland-workday christopherholland-workday commented Feb 18, 2026

  1. Validate that chatId and chatflowId are valid UUID's
  2. Ensure that the filename does not contain path traversal patterns
  3. Ensure that the sanitized filename does not contain path traversal patterns

Addresses CodeQL findings 45-50

Moved to #5842 because this PR got polluted by mistake

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @christopherholland-workday, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the security of file utility functions by introducing robust input validation for identifiers and filenames. The changes prevent potential path traversal vulnerabilities and ensure that all file-related operations are performed with validated and sanitized inputs, thereby safeguarding the system against malicious file access attempts.

Highlights

  • Input Validation: Validated that chatId and chatflowId parameters are valid UUIDs to prevent malformed inputs.
  • Path Traversal Prevention: Implemented checks to ensure that filename parameters do not contain path traversal patterns, enhancing security.
  • Post-Sanitization Filename Check: Added a validation step to verify that the filename remains safe and free of path traversal patterns even after sanitization.
Changelog
  • packages/components/src/storageUtils.ts
    • Imported isUnsafeFilePath for new validation checks.
    • Added validation for chatId to ensure it is a valid UUID.
    • Introduced checks for fileName using isUnsafeFilePath to prevent unsafe paths.
    • Implemented post-sanitization validation for sanitizedFilename to detect any remaining path separators.
  • packages/server/src/controllers/get-upload-file/index.ts
    • Imported isValidUUID and isUnsafeFilePath from flowise-components.
    • Added early validation for chatflowId and chatId to ensure they are valid UUIDs.
    • Implemented early validation for fileName using isUnsafeFilePath to catch unsafe characters at the API entry point.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
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 enhances security by adding validation for file path components like chatId, chatflowId, and fileName to prevent path traversal vulnerabilities. My review includes a critical fix to prevent a potential server crash from unhandled undefined inputs and a suggestion to remove a redundant check for improved code clarity and maintainability.

Comment on lines 759 to 761
if (isPathTraversal(chatflowId) || isPathTraversal(chatId)) {
throw new Error('Invalid path characters detected in chatflowId or chatId')
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This isPathTraversal check for chatflowId and chatId is redundant. Both variables are already validated as UUIDs in the preceding lines (line 751 for chatflowId and line 755 for chatId). A valid UUID cannot contain path traversal characters, so this check is unnecessary. Removing it will improve code clarity and remove dead code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is more of a logical "backup" if things were moved around unknowingly later on

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
* Update SECURITY.md

---------
* feat(agentflow): update canvas add node drag and drop behaviour

- fix style issues and refactor components using design token with dark mode theme support
- add and update tests with additional jest config to mock canvas and libs

* fix lint error on test

* address gemini review comments

* update README Props to match actual implementation
…5789)

* refactor(agentflow): update import paths and clean up test utilities

- Refactor import paths to use absolute paths (alias) for better readability and maintainability.
- Remove unused function `initializeDefaultNodeData` from `nodeFactory` and its related tests.
- Update `TESTS.md` to reflect the current testing status of various modules.
- Minor adjustments to Vite configuration for improved development experience.

* fix markdown format
…5806)

* feat(agentflow): enhance typography and improve node palette drawer functionality

- Add typography settings for h4, h5, and h6 in the theme configuration.
- Implement tests for typography to ensure consistency across light and dark modes.
- Refactor AddNodesDrawer to improve drag-and-drop functionality and integrate new NodeListItem component.
- Introduce useDrawerMaxHeight hook to dynamically calculate drawer height based on viewport.
- Clean up unused imports and optimize component structure for better performance.

* fix lint issues

* address review feeddback
* WIP: wiring editnode

* End to end flow

* Fixed comments

* test case added for agent flow reducer

* FIxed changes after syncing with main

* Changes to uodate interface NodeData to be in line with restapi response api/v1/nodes

* Fixed es-lint errors

* Clean code

* Fix for making failed testcase

* eslint error fixed

* fix test coverage

* Revert config.ts and vite.config.ts to main

* Fix gemini comments

* Update imports to use alias

* fix alias
Build without sourcemaps for production

Co-authored-by: Ginna Baker <ginna.baker@workday.com>
Updated all references in documentation, examples, and source files to reflect the new package name. This change ensures consistency across the project and aligns with the rebranding effort.
Co-authored-by: Natan Hoppe <natan.hoppe@evisort.com>
Co-authored-by: yau-wd <yau.ong@workday.com>
* Fix biderectional sync

* addede utility function to sync states

* Fix comment

* Normalize nodes before updating states
* fix: auth for read loginmethod endpoint

* fix: review feedback

* fix: lint issues

* fix: validate auth0 domain

* fix: lint issues

* fix: wrong loginmethod endpoint in org setup page

---------

Co-authored-by: yau-wd <yau.ong@workday.com>
… examples

- Introduced FlowStatePanel to display live flow data and saved snapshots in a resizable side panel.
- Updated BasicExample and CustomUIExample to integrate FlowStatePanel for improved user experience.
- Enhanced keyboard shortcuts for saving flow data with Cmd+S and Ctrl+S functionality.
- Updated coverage thresholds in jest.config.js to include new FlowStatePanel hooks.
- Revised TESTS.md to reflect changes in testing status for useFlowHandlers and related components.
* Always include default deny list in deny list values

* Update packages/components/src/httpSecurity.ts

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* Always include default deny list in deny list values

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: yau-wd <yau.ong@workday.com>
* Stop axios from throwing error on non-2xx response

* Sanitize Code Ran in Pyodide in CSVAgents

---------

Co-authored-by: christopherholland-workday <christopher.holland+evisort@workday.com>
* Validate command flags in MCP server config

* Validate command flag in MCP server config

* Validate MCP server config command flags

* Validate flags used in MCP server config commands

* Validate flags used in MCP server config commands
Co-authored-by: Henry Heng <henryheng@flowiseai.com>
…caping (#5747)

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
}

// Check for path traversal attempts
if (!chatId || !isValidUUID(chatId)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We didnt include chatID uuid check is because in some cases, chatID can be overriden from the API call.

For example, users can override like this:

{
   question: how are you?
   chatId: sessionABC
}

return res.status(400).send(`Invalid chatflowId format`)
}

if (!chatId || !isValidUUID(chatId)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

* Fix test coverage failures

* Fix test coverage failures

* Fix test coverage failures

* Fix test coverage failures

---------

Co-authored-by: christopherholland-workday <christopher.holland+evisort@workday.com>
Co-authored-by: christopherholland-workday <christopher.holland+evisort@workday.com>
… of sensitive cookie (#5809)

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
#5833)

* feat(agentflow): update flow date change & save handlings and enhance examples
- Introduced FlowStatePanel to display live flow data and saved snapshots in a resizable side panel.
- Updated BasicExample and CustomUIExample to integrate FlowStatePanel for improved user experience.
- Enhanced keyboard shortcuts for saving flow data with Cmd+S and Ctrl+S functionality.
- Updated coverage thresholds in jest.config.js to include new FlowStatePanel hooks.
- Revised TESTS.md to reflect changes in testing status for useFlowHandlers and related components.

* address gemini review comment

* address review comment (on example app)
* Sanitize text from DOM node

* Update packages/ui/src/views/assistants/openai/AssistantDialog.jsx

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* Update AssistantDialog.jsx

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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.

10 participants