()
| 133 | |
| 134 | |
| 135 | def main(): |
| 136 | with open(os.path.join(ROOT, "LICENSE"), encoding="utf-8") as fh: |
| 137 | root_license = fh.read() |
| 138 | |
| 139 | manifest = parse_manifest() |
| 140 | results = {} |
| 141 | |
| 142 | def check_upstream(key, dirpath, repo, pinned=None, exact_path=None): |
| 143 | fname, ours = local_license(dirpath) |
| 144 | if ours is None: |
| 145 | results[key] = ("NO-LOCAL-LICENSE", "") |
| 146 | return |
| 147 | # 1) exact upstream path (e.g. lz4 lib/LICENSE), at HEAD then pinned |
| 148 | if exact_path: |
| 149 | for ref in (None, pinned): |
| 150 | up = upstream_file(repo, exact_path, ref) |
| 151 | if up is not None and up == ours: |
| 152 | results[key] = ("IDENTICAL" if ref is None else "IDENTICAL@PINNED", |
| 153 | f"{repo}:{exact_path}") |
| 154 | return |
| 155 | # 2) default-branch detected license |
| 156 | up = upstream_default_license(repo) |
| 157 | if up is not None and up == ours: |
| 158 | results[key] = ("IDENTICAL", f"{repo} (default branch)") |
| 159 | return |
| 160 | # 3) pinned-commit candidates by filename |
| 161 | if pinned: |
| 162 | tried = [fname] + [c for c in CANDIDATE_NAMES if c != fname] |
| 163 | for cand in tried: |
| 164 | up2 = upstream_file(repo, cand, pinned) |
| 165 | if up2 is not None and up2 == ours: |
| 166 | results[key] = ("IDENTICAL@PINNED", f"{repo}:{cand}@{pinned}") |
| 167 | return |
| 168 | # 4) HEAD candidates by filename |
| 169 | for cand in CANDIDATE_NAMES: |
| 170 | up3 = upstream_file(repo, cand) |
| 171 | if up3 is not None and up3 == ours: |
| 172 | results[key] = ("IDENTICAL", f"{repo}:{cand} (default branch)") |
| 173 | return |
| 174 | results[key] = ("DIFFERS" if up is not None else "ERROR", f"{repo}") |
| 175 | |
| 176 | # Libraries |
| 177 | for rel, (repo, exact) in LIBS.items(): |
| 178 | check_upstream(rel, os.path.join(ROOT, rel), repo, exact_path=exact) |
| 179 | |
| 180 | # Special: nomic = canonical Apache-2.0 text; sqlite3 = first-party notice |
| 181 | # |
| 182 | # This used to `curl` https://www.apache.org/licenses/LICENSE-2.0.txt at |
| 183 | # gate time and byte-compare. A gating verdict must not depend on a live |
| 184 | # HTTP request: any fetch failure yielded an empty string, compared unequal, |
| 185 | # and reported DIFFERS -- indistinguishable from a real licence change. That |
| 186 | # is what reddened `security / license-gate` on PR #1337 for over two weeks, |
| 187 | # on a branch touching three CLI files and no licence at all. |
| 188 | # |
| 189 | # The canonical Apache-2.0 text is immutable and versioned, so it is pinned |
| 190 | # by digest instead. Verified byte-identical to the upstream text at the time |
| 191 | # of pinning (11358 bytes). A mismatch now means our vendored copy changed -- |
| 192 | # which is exactly, and only, what this audit is meant to detect. |
no test coverage detected