Skip to content

github-url host regex is hardcoded to github.com, blocking GitHub Enterprise Server #39

Description

@blinkagent

Summary

agents-chat-action cannot be used on GitHub Enterprise Server (GHES) because the github-url input is validated against a regex that is hardcoded to github.com. On GHES, every valid issue/PR URL (e.g. https://github.example.com/owner/repo/pull/1) fails validation and the action exits before ever posting a comment.

Where

src/comment.ts lines 20-21:

const GITHUB_URL_REGEX =
    /^https:\/\/github\.com\/([^/]+)\/([^/]+)\/(?:issues|pull)\/(\d+)\/?(?:[?#].*)?$/;

The same restriction is echoed in:

  • src/action.ts — error message: "The action rejects non-github.com hosts ..."
  • README.mdgithub-url input docs: "only https://github.com/<owner>/<repo>/... are accepted"

Proposal

Anchor the regex to the runner-provided GITHUB_SERVER_URL env var instead of the literal string github.com. The Actions runner always sets GITHUB_SERVER_URL to the current server (https://github.com on dotcom, https://github.example.com on GHES), so this makes the action portable without weakening the existing security property — the host anchor is still runner-controlled, not user-controlled, so a workflow that templates user input into github-url still cannot redirect the action to an attacker-chosen host.

Rough shape:

  1. In src/comment.ts, replace the module-level constant with a builder that escapes regex metacharacters in the host:
    export function buildGithubURLRegex(serverURL: string): RegExp {
        const base = serverURL.replace(/\/$/, "").replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
        return new RegExp(
            `^${base}/([^/]+)/([^/]+)/(?:issues|pull)/(\\d+)/?(?:[?#].*)?$`,
        );
    }
  2. Have parseGithubItemURL accept the server URL (plumbed in from action.ts, consistent with the existing pattern of keeping process.env reads at the edge). Provide a https://github.com fallback for tests / non-Actions callers.
  3. Update the error message in action.ts and the github-url row in README.md to describe the accepted host as "the current GitHub server ($GITHUB_SERVER_URL)" rather than github.com.
  4. Add tests in src/comment.test.ts:
    • dotcom URL still parses,
    • a GHES URL (e.g. https://github.acme.example/owner/repo/pull/1) parses when GITHUB_SERVER_URL matches,
    • a URL whose host does not match GITHUB_SERVER_URL is still rejected (the security-relevant case).

Open questions

  • Read GITHUB_SERVER_URL inside the helper, or plumb it through ActionInputs? The rest of the codebase keeps env reads at the edge, so plumbing it in is more consistent but changes the parseGithubItemURL signature that comment.test.ts calls directly.
  • Confirm the fallback host when GITHUB_SERVER_URL is unset (only relevant outside a real Actions runner). Presumably https://github.com.

Created on behalf of @mdanter

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions