louislam/uptime-kuma · error · Error

Invalid service name. Only alphanumeric characters and '.',

Error message

Invalid service name. Only alphanumeric characters and '.', '_', '-' are allowed.

What it means

Thrown by checkWindows() when the service name fails the regex ^[A-Za-z0-9._-]+$. This guard exists to reduce command-injection risk before interpolating the name into a PowerShell Get-Service command. Note: the Windows regex is stricter than the Linux one — it does NOT allow '@', which the systemd path permits.

Source

Thrown at server/monitor-types/system-service.js:77

                heartbeat.status = UP;
                heartbeat.msg = `Service '${serviceName}' is running.`;
                resolve();
            });
        });
    }

    /**
     * Windows Check (PowerShell)
     * @param {string} serviceName The name of the service to check.
     * @param {object} heartbeat The heartbeat object.
     * @returns {Promise<void>} Resolves on success, rejects on error.
     */
    async checkWindows(serviceName, heartbeat) {
        return new Promise((resolve, reject) => {
            // SECURITY: Validate service name to reduce command-injection risk
            if (!/^[A-Za-z0-9._-]+$/.test(serviceName)) {
                throw new Error("Invalid service name. Only alphanumeric characters and '.', '_', '-' are allowed.");
            }

            const cmd = "powershell";
            const args = [
                "-NoProfile",
                "-NonInteractive",
                "-Command",
                `(Get-Service -Name '${serviceName.replaceAll("'", "''")}').Status`,
            ];

            execFile(cmd, args, { timeout: 5000 }, (error, stdout, stderr) => {
                let output = (stderr || stdout || "").toString().trim();
                if (output.length > 200) {
                    output = output.substring(0, 200) + "...";
                }

                if (error || stderr) {
                    reject(new Error(`Service '${serviceName}' is not running/found.`));

View on GitHub (pinned to 6b5ea01557)

Solutions

  1. Open services.msc and copy the internal Service Name (not the Display Name) — it is usually short and alphanumeric.
  2. Remove any spaces, '@', or symbol characters from the configured name.
  3. If the real Windows service name contains a disallowed character, file a feature request to widen the allow-list safely rather than bypassing the guard.
  4. Run the same regex test locally before saving: /^[A-Za-z0-9._-]+$/.test(name).
Defensive patterns

Strategy: validation

Validate before calling

function isValidWindowsServiceName(name) { return /^[A-Za-z0-9._-]+$/.test(name); }

Type guard

function isValidWindowsServiceName(name) { return typeof name === "string" && /^[A-Za-z0-9._-]+$/.test(name); }

Try / catch

if (!isValidWindowsServiceName(serviceName)) { heartbeat.status = DOWN; heartbeat.msg = "Invalid service name"; return; }

Prevention

When it happens

Trigger: Produced on Windows when system_service_name contains any character outside [A-Za-z0-9._-], including spaces, '@', slashes, parentheses, or non-ASCII characters.

Common situations: User pastes a service DisplayName (which often has spaces) instead of the internal Service Name; name includes '@' (allowed on Linux but rejected on Windows); copy-paste introduced an invisible character or trailing newline; the service genuinely has a name with an unusual character.

Related errors


AI-assisted analysis of louislam/uptime-kuma@6b5ea01557 (2026-08-12). Data as JSON: /api/errors/1149f5c0311a1f1f. Report an issue: GitHub.