DevOps-zhuang / copilot-metric-saver

call github copilot usage and seat API, then save fetched data to file or mysql for persistent save, then anlyze it.
2 stars 3 forks source link

Fix code scanning alert no. 3: Uncontrolled data used in path expression #9

Closed DevOps-zhuang closed 3 weeks ago

DevOps-zhuang commented 3 weeks ago

Fixes https://github.com/DevOps-zhuang/copilot-metric-saver/security/code-scanning/3

To fix the problem, we need to ensure that the constructed file path is contained within a safe root directory. This can be achieved by normalizing the path using path.resolve and then checking that the normalized path starts with the root directory. This approach prevents directory traversal attacks by ensuring that any .. segments are resolved within the root directory.

  1. Normalize the constructed file path using path.resolve.
  2. Check that the normalized path starts with the root directory.
  3. If the check fails, handle the error appropriately (e.g., log the error and throw an exception).

Suggested fixes powered by Copilot Autofix. Review carefully before merging.