Skip to content

authorisedList entries with * never match repository URLs #1589

Description

@cniska-oura

Describe the bug

getRepoByUrl performs an exact URL lookup on authorisedList. Entries intended as org-level wildcards, e.g. https://github.com/example-org/*, do not match concrete repo URLs such as https://github.com/example-org/some-repo.git. There is no way to allowlist all repos under an org without enumerating every URL.

To Reproduce

Steps to reproduce the behavior:

  1. Run @finos/git-proxy@2.0.0.
  2. Add an authorised list entry: { "url": "https://github.com/example-org/*" }
  3. Clone or pull https://github.com/example-org/some-repo through the proxy.
  4. See error: repo not found on authorised list / request rejected as unauthorised.

Expected behavior

https://github.com/example-org/* should match any repo under that org, e.g. https://github.com/example-org/foo and https://github.com/example-org/foo.git. For github.com, repo URLs are always owner/repo. Exact URL entries should continue to work as today.

Screenshots

N/A

Desktop (please complete the following information):

  • OS: Linux; macOS
  • Browser: N/A (HTTP client / git CLI)
  • Version: Node 20+; @finos/git-proxy 2.0.0

Smartphone (please complete the following information):

  • Device: N/A
  • OS: N/A
  • Browser: N/A
  • Version: N/A

Additional context

Suggested fallback when exact lookup misses:

function wildcardToRegExp(pattern) {
  const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, '\\$&');
  return new RegExp('^' + escaped.replace(/\*/g, '[^/]+') + '$');
}

const originalGetRepoByUrl = db.getRepoByUrl;
db.getRepoByUrl = async function (url) {
  const exact = await originalGetRepoByUrl(url);
  if (exact) return exact;
  for (const repo of await db.getRepos()) {
    if (repo.url?.includes('*') && wildcardToRegExp(repo.url).test(url)) {
      return repo;
    }
  }
  return null;
};

Happy to open a PR if useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions