Composer
Pratique takes the place of Packagist for Composer, at /composer. Composer differs from npm and Python in a few ways that matter for security, and this page explains them.
The examples use https://pratique.example.com. Use your own server's public URL.
Connect clients in the web UI shows these settings for your server, and the token page shows
them with your token filled in. To create a token, see access tokens.
Set up Composer
Add Pratique as a repository in composer.json, and turn off Packagist. Without
"packagist.org": false, Composer still asks Packagist and can download around Pratique.
{
"repositories": [
{"type": "composer", "url": "https://pratique.example.com/composer"},
{"packagist.org": false}
]
}
Put your token in auth.json, next to composer.json or in Composer's home folder. Do not
commit it.
{"http-basic": {"pratique.example.com": {"username": "token", "password": "YOUR_TOKEN"}}}
You can also store it with Composer itself, or give it to a CI job in the COMPOSER_AUTH environment
variable, which holds the same JSON:
composer config --global http-basic.pratique.example.com token YOUR_TOKEN
export COMPOSER_AUTH='{"http-basic": {"pratique.example.com": {"username": "token", "password": "YOUR_TOKEN"}}}'
Plain HTTP
Composer refuses plain HTTP by default. For a trial on your own machine, the Connect clients
page adds this to composer.json:
"config": {"secure-http": false}
Remove it, and use HTTPS, before anyone uses Pratique over a network.
How Composer is different
No published hashes
Packagist publishes no file hashes, so Pratique cannot compare a download with a hash from the registry. Instead, it pins two things for each release:
- The Git commit that the release was built from. If a tag later moves to a different commit, the release is refused and an incident opens.
- The hash of its first download. Pratique keeps that file and checks it against the hash on each delivery. Storage cleanup never removes these files, because they cannot always be fetched again identically.
In firewall mode, Pratique keeps no stored copy, and GitHub can build the same commit into a different zip. So only the commit is checked there, not the bytes. See firewall mode.
Quarantine dates
Packagist's dates can come from Git, and an author can backdate a Git commit. So a new release's quarantine clock starts when Pratique first sees it, not at the date Packagist gives.
The first time Pratique sees a whole package, it has no history, so it accepts the dates from upstream. Request your important packages through Pratique early.
No Git sources
Pratique removes every release's Git source, so Composer cannot clone around the proxy. A release with no downloadable archive is not offered.
Development branches, such as dev-main, are not offered either. They move all the time and
cannot be pinned to a release.
Allowed archive hosts
Composer archives may only come from codeload.github.com, api.github.com,
gitlab.com and bitbucket.org. To change the list, set
PRATIQUE_COMPOSER_DIST_HOSTS, or upstreams.composer_dist_hosts in the config file. See
configuration.
Scripts and plugins
Composer runs scripts only from your own project, not from dependencies. Plugins do run code during install.
Review the Composer plugins risk rule together with Composer's own allow-plugins
setting. See risk rules.
Held and refused versions
Pratique leaves held and refused versions out of the Composer listing. Composer then picks the newest cleared version that fits your constraints.
- If only a held version fits a constraint, Composer cannot resolve it, and reports that no matching version was found. Open the package page in Pratique to see why.
- If no version of a package is cleared, the listing is refused with HTTP 403, and the message says "no version of vendor/package is cleared", with the reason for the newest one and a link to the package page.
- If
composer.lockpins a held or refused version, the download is refused with HTTP 403, and the message gives the reason and the link.
Lockfiles
composer.lock records where each archive is downloaded from. Through Pratique, these addresses
are on Pratique, under /composer/dists/. A lockfile made before you moved to Pratique points at
api.github.com or other hosts, and includes Git sources.
pratique lockcheck reads composer.lock and fails on any source or archive address that
is not on Pratique. Regenerate the lockfile with Pratique as the only repository, and review the version changes. See CI.
Keep api.github.com and codeload.github.com blocked at your network edge. A gateway
cannot redirect them, because they serve far more than packages. See
block direct access.
Private packages
Composer has no publish command. In artifactory mode, you upload a zip that contains
composer.json, with a token that has publish access:
curl -u token:YOUR_TOKEN --upload-file package.zip \
'https://pratique.example.com/composer/upload?version=1.0.0'
The package name must match a reserved pattern, such as acme/*. See
private packages.