finos / finos/git-proxy

authorisedList entries with * never match repository URLs

Open
#1,589 3 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
249
Forks
176
Avg merge
3d 8h
Merged PRs (30d)
20

Description

**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:

```js
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.