这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@timothycarambat
Copy link
Member

Enforce more strict validations on document tree modification endpoints that can accept a user input.

@review-agent-prime
Copy link

server/utils/files/index.js

Consider adding comments to the newly introduced isWithin function to explain its purpose and how it works. This will improve the readability of the code and make it easier for other developers to understand.
Create Issue
See the diff
Checkout the fix

    /**
     * Checks if a given path is within another path.
     * @param {string} outer - The outer path.
     * @param {string} inner - The inner path.
     * @returns {boolean} - Returns true if the inner path is within the outer path, false otherwise.
     */
    function isWithin(outer, inner) {
      if (outer === inner) return false;
      const rel = path.relative(outer, inner);
      return !rel.startsWith("../") && rel !== "..";
    }
git fetch origin && git checkout -b ReviewBot/The-c-7tse65b origin/ReviewBot/The-c-7tse65b

Consider adding error handling to the isWithin function to handle cases where the provided paths are not valid. This will improve the robustness of the code and make it more resilient to unexpected inputs.
Create Issue
See the diff
Checkout the fix

    function isWithin(outer, inner) {
      try {
        if (outer === inner) return false;
        const rel = path.relative(outer, inner);
        return !rel.startsWith("../") && rel !== "..";
      } catch (error) {
        console.error(`Error checking if path ${inner} is within path ${outer}: ${error}`);
        return false;
      }
    }
git fetch origin && git checkout -b ReviewBot/The-c-tc5dser origin/ReviewBot/The-c-tc5dser

@timothycarambat timothycarambat merged commit 8a7324d into master Jan 19, 2024
@timothycarambat timothycarambat deleted the strict-check-doc-folder-commands branch January 19, 2024 20:56
cabwds pushed a commit to cabwds/anything-llm that referenced this pull request Jul 3, 2025
* Employ strict validations on document pathing

* add comment

* update validSubfolder var
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