{"schema_version":"1.7.4","id":"OSEC-2023-01","modified":"2026-01-09T12:00:00Z","published":"2023-05-25T12:00:00Z","summary":"Time of check time of use issue in opam's cache","details":"## Bug description\n\nOpam uses since version 2.0.0 a download cache: if a source artifact is needed, first its hash is looked up in the local cache (~/.opam/download-cache//). Opam supports multiple hash algorithms, a cache lookup tries all hash algorithms present in the opam file. Before opam 2.1.5, the hash of a cache entry as encoded in its file name was trusted and not checked against its content.\n\nIf a package specifies only a single (non-weak) hash algorithm, this lead to the source artifact taken as is, any error while writing the artifact into the cache, or reading it from the cache, was not detected. Also, in certain setups, if the download cache is shared (writable) across containers (for example in some CI systems), this leads to the possibility of cache poisoning.\n\nThanks to Raja and Kate, the issue was fixed in [PR 5538](https://github.com/ocaml/opam/pull/5538)\n\n## Timeline\n\nThe timeline of this issue is as follows:\n\n- Feb 23rd 2023 conducted black-box security audit of opam\n- Feb 24th 2023 reported to the opam team\n- Feb 27th 2023 video meeting with the opam team, explaining the issue further\n- Mar 27th 2023 initial review meeting of the patches developed by the opam team\n- May 9th 2023 public PR fixing the issue discovered\n- May 25th 2023 release of opam 2.1.5","affected":[{"package":{"ecosystem":"opam","name":"opam-repository","purl":"pkg:opam/opam-repository"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"2"},{"fixed":"2.1.5"}]},{"type":"GIT","repo":"git+https://github.com/ocaml/opam","events":[{"fixed":"7a538fd0bf3b3956d84bb25d0f6b1126fa177595"},{"introduced":"cfa4e77b49d0bccaf5c91b2e6f36089aab5e0540"}]}],"versions":["pkg:opam/opam-repository@2.0.0","pkg:opam/opam-repository@2.0.0~beta?repository=git%2Bhttps:%2F%2Fgithub.com%2Focaml%2Fopam-repository-archive.git","pkg:opam/opam-repository@2.0.0~beta3?repository=git%2Bhttps:%2F%2Fgithub.com%2Focaml%2Fopam-repository-archive.git","pkg:opam/opam-repository@2.0.0~beta3.1?repository=git%2Bhttps:%2F%2Fgithub.com%2Focaml%2Fopam-repository-archive.git","pkg:opam/opam-repository@2.0.0~beta5?repository=git%2Bhttps:%2F%2Fgithub.com%2Focaml%2Fopam-repository-archive.git","pkg:opam/opam-repository@2.0.0~rc?repository=git%2Bhttps:%2F%2Fgithub.com%2Focaml%2Fopam-repository-archive.git","pkg:opam/opam-repository@2.0.0~rc2","pkg:opam/opam-repository@2.0.0~rc3?repository=git%2Bhttps:%2F%2Fgithub.com%2Focaml%2Fopam-repository-archive.git","pkg:opam/opam-repository@2.0.1","pkg:opam/opam-repository@2.0.10","pkg:opam/opam-repository@2.0.2","pkg:opam/opam-repository@2.0.3","pkg:opam/opam-repository@2.0.4","pkg:opam/opam-repository@2.0.5","pkg:opam/opam-repository@2.0.6","pkg:opam/opam-repository@2.0.7","pkg:opam/opam-repository@2.0.8","pkg:opam/opam-repository@2.0.9","pkg:opam/opam-repository@2.0~alpha5?repository=git%2Bhttps:%2F%2Fgithub.com%2Focaml%2Fopam-repository-archive.git","pkg:opam/opam-repository@2.1.0","pkg:opam/opam-repository@2.1.0~beta2?repository=git%2Bhttps:%2F%2Fgithub.com%2Focaml%2Fopam-repository-archive.git","pkg:opam/opam-repository@2.1.0~beta4","pkg:opam/opam-repository@2.1.0~rc?repository=git%2Bhttps:%2F%2Fgithub.com%2Focaml%2Fopam-repository-archive.git","pkg:opam/opam-repository@2.1.0~rc2?repository=git%2Bhttps:%2F%2Fgithub.com%2Focaml%2Fopam-repository-archive.git","pkg:opam/opam-repository@2.1.1","pkg:opam/opam-repository@2.1.2","pkg:opam/opam-repository@2.1.3","pkg:opam/opam-repository@2.1.4"],"ecosystem_specific":{"opam_constraint":"opam-repository {>= \"2\" & < \"2.1.5\"}"}}],"references":[{"type":"FIX","url":"https://github.com/ocaml/opam/pull/5538"},{"type":"ARTICLE","url":"https://opam.ocaml.org/blog/opam-2-1-5-local-cache/"}],"credits":[{"name":"Reynir Björnsson","type":"REPORTER"},{"name":"Hannes Mehnert","type":"REPORTER"},{"name":"Kate","type":"REMEDIATION_DEVELOPER"},{"name":"Raja Boujbel","type":"REMEDIATION_REVIEWER"}],"database_specific":{"osv":"https://github.com/ocaml/security-advisories/tree/generated-osv/2023/OSEC-2023-01.json","human_link":"https://github.com/ocaml/security-advisories/tree/main/advisories/2023/OSEC-2023-01.md"}}