TechnitiumSoftware/DnsServer · error · DnsServerException

The application name is invalid: {applicationName}

Error message

The application name is invalid: {applicationName}

What it means

Thrown by InstallApplicationAsync when the resolved absolute application folder does not start with _appsPath + DirectorySeparatorChar. It is a path-traversal guard: applicationName must resolve to a directory strictly inside the apps root.

Source

Thrown at DnsServerCore/Dns/Applications/DnsApplicationManager.cs:379

            await Task.WhenAll(tasks);

            RefreshAppObjectLists();
        }

        public async Task<DnsApplication> InstallApplicationAsync(string applicationName, Stream appZipStream)
        {
            foreach (char invalidChar in Path.GetInvalidFileNameChars())
            {
                if (applicationName.Contains(invalidChar))
                    throw new DnsServerException("The application name contains an invalid character: " + invalidChar);
            }

            if (_applications.ContainsKey(applicationName))
                throw new DnsServerException("DNS application already exists: " + applicationName);

            string applicationFolder = Path.GetFullPath(Path.Combine(_appsPath, applicationName));
            if (!applicationFolder.StartsWith(_appsPath + Path.DirectorySeparatorChar))
                throw new DnsServerException("The application name is invalid: " + applicationName);

            if (Directory.Exists(applicationFolder))
                Directory.Delete(applicationFolder, true);

            Directory.CreateDirectory(applicationFolder);

            //keep a copy of the zip file in the application folder for transferring to other nodes
            await using (FileStream zipCopyStream = new FileStream(Path.Combine(applicationFolder, applicationName + ".zip"), FileMode.Create, FileAccess.ReadWrite))
            {
                await appZipStream.CopyToAsync(zipCopyStream);

                zipCopyStream.Position = 0;

                await using (ZipArchive appZip = new ZipArchive(zipCopyStream, ZipArchiveMode.Read, false, Encoding.UTF8))
                {
                    try
                    {
                        await appZip.ExtractToDirectoryAsync(applicationFolder, true);

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Reject names containing '..', Path.AltDirectorySeparatorChar, or any GetInvalidFileNameChars before calling InstallApplicationAsync.
  2. Restrict names to a safe whitelist regex like ^[A-Za-z0-9._-]+$.
  3. Verify Path.GetFullPath(Path.Combine(_appsPath, name)) + separator is still under _appsPath + separator before install.
  4. On case-insensitive OSes, compare with StringComparison.OrdinalIgnoreCase after both paths are normalized.

Example fix

// before
await appManager.InstallApplicationAsync(appName, zip);

// after
if (!System.Text.RegularExpressions.Regex.IsMatch(appName, @"^[A-Za-z0-9._-]+$"))
    throw new ArgumentException("Invalid app name", nameof(appName));
await appManager.InstallApplicationAsync(appName, zip);
Defensive patterns

Strategy: validation

Validate before calling

static readonly Regex SafeName = new(@"^[A-Za-z0-9._-]+$");
bool IsSafeAppName(string n) => !string.IsNullOrWhiteSpace(n) && SafeName.IsMatch(n) && !n.Contains("..");

Type guard

static bool IsValidAppName(string name) =>
    !string.IsNullOrWhiteSpace(name)
    && System.Text.RegularExpressions.Regex.IsMatch(name, @"^[A-Za-z0-9._-]+$");

Try / catch

if (!IsValidAppName(name)) return BadRequest("Invalid app name");
try { await mgr.InstallApplicationAsync(name, zip); }
catch (DnsServerException ex) when (ex.Message.Contains("name is invalid")) { return BadRequest(ex.Message); }

Prevention

When it happens

Trigger: applicationName containing relative segments (..), rooted paths (C:\x, /x), or OS-specific separators that, after Path.GetFullPath, escape _appsPath. On case-insensitive filesystems a different-cased prefix can also slip past StartsWith.

Common situations: User-supplied app name from a form/API not sanitized; names like '../existing', '\\?\C:\evil', or containing backslashes on Linux where _appsPath uses '/'. A name that exactly equals _appsPath (no child segment) also fails because the separator is appended.

Related errors


AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13). Data as JSON: /api/errors/99af30fb80803b5d. Report an issue: GitHub.