Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-26838

Utility API to check if a file is physically inside a given directory

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor Minor
    • core

      Commonly need to verify that file paths provided by a user are really relative and do not refer to locations outside a workspace or the like. Should have something in Util along the lines of

      public static boolean isInside(File root, File f) throws IOException {
          String path = f.getCanonicalPath();
          String rootPath = root.getCanonicalPath();
          return path.equals(rootPath) || path.startsWith(rootPath + File.separatorChar);
      }
      

      and a matching method in FilePath.

            Unassigned Unassigned
            jglick Jesse Glick
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: