Proving You Own a Repository When There Is No API to Ask

Aug 18, 2026 9 min read 359 views
Proving You Own a Repository When There Is No API to Ask

The API you cannot call

extdir lets a maintainer remove their own extension without asking anyone. To do that, we need to answer a simple question: does this person control the repository?

For GitHub, this is easy. Sign the maintainer in, use their token once, and ask:

GET /repos/{owner}/{repo}

The response has a permissions object. Read access does not prove anything because every public repository gives read access to everyone. push or admin tells us that the user can actually maintain the repository. GitHub already knows this, so there is no reason to build it ourselves.

Then there is everything else.

Forty-two extensions with no API to ask

Host Extensions
bitbucket.org 31
gitlab.com 5
self-hosted GitLab 3
codeberg.org 1
unknown self-hosted 2

That is 42 out of 423 extensions. Bitbucket alone accounts for three quarters of them, so a solution that only handles GitLab is not enough.

We cannot ask these hosts for repository permissions. There is no common API, no token, and for git.schubwerk.com and git.optiweb.serv.si we do not even know which software they are running. Two of the GitLab instances are also self-hosted.

So instead of asking the forge, we ask the repository itself.

We publish a file that only someone with write access can publish, then fetch it once.

A token with nowhere to store it

The obvious design is a challenge table. Generate a token, store it with an expiry time, and clean it up later.

I did not build that. It creates state for every verification that someone starts and never finishes. It also means we now have another piece of state that can become stale or incorrect.

Instead, the token is derived from the user and extension:

hash_hmac(
    'sha256',
    sprintf('extdir-ownership:%s:%s', $userId, $extensionId),
    $appSecret,
);

It is deterministic, so we can calculate it whenever we need it. It cannot be guessed without APP_SECRET. There is no table, no cleanup job, and no unfinished verification state.

The token is tied to both the user and the extension. This is important.

The verification file is public, so anyone can read it. But the token only verifies one specific account. If someone else copies the file, they still cannot use it for their own account because their token is different.

The file is called extdir-verification.txt and lives at the repository root.

It is deliberately not a dotfile. Some forge web interfaces hide files that start with a dot. If a maintainer cannot see the file they just committed, they may assume the verification is broken.

Raw URLs instead of APIs

To fetch the file, we need to know how each forge serves raw repository content. The paths are different:

Forge Path
GitLab {base}/{path}/-/raw/{branch}/{file}
Gitea, Codeberg {base}/{owner}/{repo}/raw/branch/{branch}/{file}
Bitbucket {base}/{ws}/{repo}/raw/{branch}/{file}

Using raw URLs instead of each forge's API is a deliberate tradeoff.

An API gives better error messages, but we would need separate implementations for each forge and would often need authentication.

Raw URLs also work the same way for gitlab.com and self-hosted GitLab. That matters because some of the GitLab repositories are self-hosted.

For unknown forges, we try all three URL formats with both main and master. The repositories cover about a decade, so some of them still use master.

The dangerous part

This feature is different from normal fetching in one important way: the URL comes from Packagist metadata, and anyone can publish a package with any repository URL they want.

For example, a package could point to:

http://169.254.169.254/latest/meta-data/

If a maintainer clicks "check now", our server would make that request from inside the hosting environment.

The result would then tell the attacker something about the response. This is server-side request forgery, or SSRF.

The on-demand nature makes this especially useful to an attacker. They control the URL and can trigger the request when they want.

Every rule in the fetcher exists to prevent this:

  • HTTPS only. HTTP is not allowed. file:// is not allowed because it is not a network request.
  • Address filtering. Loopback, private, link-local, unique-local, and carrier-grade NAT addresses are rejected for both IPv4 and IPv6. Link-local addresses are especially important because 169.254.169.254 is commonly used for cloud instance metadata.
  • Pinned DNS resolution. We resolve the hostname once and use that exact address for the request. If we check DNS and then let the HTTP client resolve the hostname again, DNS rebinding could make the first lookup public and the second lookup private.
  • No redirects. A public server could redirect the request to a private address. Following redirects would bypass the address checks.
  • 8 KB response limit. The verification file is less than 100 bytes. There is no reason to read an unlimited response.

There is one more important rule: the caller never gets the response body for display.

The fetcher returns a string that the caller checks for the expected token and then discards.

This prevents a failed verification from becoming a way to read arbitrary internal pages.

If a hostname resolves to both a public and a private address, we reject it completely. We do not pick the public address and continue. That situation can be part of an attack.

Testing something that must never send a request

The important part of these checks is that dangerous requests are rejected before any HTTP request is made.

The tests verify this directly. The mock HTTP client is not given any responses. If the code tries to use it, the test fails.

Two early tests were using real DNS. That made the security component depend on the network and made it difficult to test in places where there was no connection.

DNS resolution now sits behind a small interface. Tests can provide whatever addresses they need without using the network. This also lets us test cases that are difficult to produce with a real resolver, such as a hostname that resolves to both a public and a private address.

There are 21 tests and they run without network access.

The address filter is the part of this code I would least like to get wrong.

What it still cannot do

The verification file proves repository control at one point in time.

A maintainer who leaves a company can keep the verification file in the repository until someone removes it. A compromised CI pipeline could also publish the file.

For this feature, that is acceptable.

The claim only gives the user the ability to remove an extension from the directory. The impact of a false positive is one delisting, which can be reversed by email. The moderation log also records who performed the action and what evidence they used.

The verification code and tests are public:

extdir.com

Source code is available on GitHub.

AM

Author Amer Malik Mohammed

Full-Stack Developer with 2+ years of experience in object-oriented PHP development (Symfony), JavaScript and MySQL. Specialized in e-commerce solutions (Shopware 5/6), REST API development and process automation in agile teams.

Contact author