{"record":{"id":"6a4bb19edbadb97d","repo":"peass-ng/PEASS-ng","slug":"network-path-is-not-allowed-for-directory-junction","errorCode":null,"errorMessage":"Network path is not allowed for directory junction: [{0}]","messagePattern":"Network path is not allowed for directory junction: \\[(.+?)\\]","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/Directory Class/Directory Core Methods/Directory.CreateJunctionCore.cs","lineNumber":78,"sourceCode":"      {\n         if (pathFormat != PathFormat.LongFullPath)\n         {\n            Path.CheckSupportedPathFormat(directoryPath, true, true);\n            Path.CheckSupportedPathFormat(junctionPath, true, true);\n\n            directoryPath = Path.GetExtendedLengthPathCore(transaction, directoryPath, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator);\n            junctionPath = Path.GetExtendedLengthPathCore(transaction, junctionPath, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator);\n\n            pathFormat = PathFormat.LongFullPath;\n         }\n\n\n         // Directory Junction logic.\n\n\n         // Check if drive letter is a mapped network drive.\n         if (new DriveInfo(directoryPath).IsUnc)\n            throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.Network_Path_Not_Allowed, directoryPath), \"directoryPath\");\n\n         if (new DriveInfo(junctionPath).IsUnc)\n            throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.Network_Path_Not_Allowed, junctionPath), \"junctionPath\");\n\n\n         // Check for existing file.\n         File.ThrowIOExceptionIfFsoExist(transaction, false, directoryPath, pathFormat);\n         File.ThrowIOExceptionIfFsoExist(transaction, false, junctionPath, pathFormat);\n\n\n         // Check for existing directory junction folder.\n         if (File.ExistsCore(transaction, true, junctionPath, pathFormat))\n         {\n            if (overwrite)\n            {\n               DeleteDirectoryCore(transaction, null, junctionPath, true, true, true, pathFormat);\n\n               CreateDirectoryCore(true, transaction, junctionPath, null, null, false, pathFormat);","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/Directory Class/Directory Core Methods/Directory.CreateJunctionCore.cs#L60-L96","documentation":"CreateJunctionCore rejects junction targets (directoryPath) that are UNC/network paths. Junctions (NTFS reparse points of type mount point) cannot point to network shares, so AlphaFS pre-checks new DriveInfo(directoryPath).IsUnc and throws ArgumentException with Resources.Network_Path_NotAllowed before making any native call.","triggerScenarios":"Calling Directory.CreateJunction (or CreateJunctionTransacted) with a junctionWanted/target path starting with \"\\\\\\\\\" (UNC, e.g. \\\\\\\\server\\\\share\\\\dir) or a mapped drive whose underlying provider is UNC.","commonSituations":"Trying to junction to a network share to 'link' remote storage locally; a drive letter that is actually a mapped network drive (DriveInfo.IsUnc true after provider resolution); build scripts linking to \\\\\\\\server\\\\projects; misconfigured deploy targets.","solutions":["Use a symbolic link instead of a junction: symlinks can target UNC paths (Directory.CreateSymbolicLink / mklink /D), keeping in mind they need admin or Developer Mode on older Windows.","Junction to a local staging copy: copy or mount the share to a local path (e.g. via `net use` mapped drive is NOT enough — it's still UNC-backed) and junction to a genuine local directory.","Validate the target before calling: new DriveInfo(target).IsUnc or target.StartsWith(@\"\\\\\") and fail with your own message.","If the share must appear at a fixed path, use DFS or SMB mapping at the OS level rather than a junction."],"exampleFix":"// before\nDirectory.CreateJunction(@\"C:\\links\\\\data\", @\"\\\\\\\\server\\\\share\\\\data\");\n// after\n// Symlinks may point to UNC paths; junctions may not.\nDirectory.CreateSymbolicLink(@\"C:\\links\\\\data\", @\"\\\\\\\\server\\\\share\\\\data\", true);","handlingStrategy":"validation","validationCode":"static void EnsureLocalJunctionTarget(string target)\n{\n    bool isUnc = target.StartsWith(@\"\\\\\")\n        || (target.Length >= 2 && new DriveInfo(target.Substring(0, 1) + @\":\\\\\").DriveType == DriveType.Network);\n    if (isUnc)\n        throw new ArgumentException($\"Junction target must be a local path: {target}\");\n}\nEnsureLocalJunctionTarget(targetPath);\nDirectory.CreateJunction(linkPath, targetPath);","typeGuard":"static bool IsLocalFileSystemPath(string p) =>\n    !p.StartsWith(@\"\\\\\") &&\n    new DriveInfo(Path.GetPathRoot(Path.GetFullPath(p))).DriveType != DriveType.Network;","tryCatchPattern":"try\n{\n    Directory.CreateJunction(linkPath, targetPath);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Network path is not allowed\"))\n{\n    // fall back to symlink, which supports UNC targets\n    Directory.CreateSymbolicLink(linkPath, targetPath, true);\n}","preventionTips":["Remember the rule: junctions = local target only; symlinks may point to UNC.","Treat mapped drives as network (DriveType.Network), not local.","Check DriveInfo(...).IsUnc on both endpoints before creating reparse points.","Document in tooling that junction targets must be local NTFS paths."],"tags":["junction","unc-path","network","argumentexception","alphafs"],"backgroundTag":"junction-unc-path-not-allowed","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}