From bea15f993f40e04834ed7e1ab5d9edc82537c3cb Mon Sep 17 00:00:00 2001 From: Foothills Digital Date: Fri, 6 Nov 2026 09:39:04 -0700 Subject: [PATCH 1/2] fix(submit): reject a standard license with a restriction tacked on A LICENSE that was the MIT text plus "you may not use this commercially" passed, because the phrase match only looked for MIT's own wording. Once a license file (by phrase, SPDX line or one-line name) or a README License section is recognised, it is now also checked for added restriction wording: may not be used commercially or sold, commercial use prohibited or needing a paid license, and personal/educational/non-commercial use only. A hit fails as " with an added restriction". The reason is a fixed string and never quotes the file, since it is posted publicly. The patterns stick to wording that restricts. A test checks that no canonical fixture trips them except CC BY-NC, which really does. --- scripts/devstream/license_detect.py | 29 ++++++++++++++++++++++++++++ scripts/tests/test_license_detect.py | 21 ++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/scripts/devstream/license_detect.py b/scripts/devstream/license_detect.py index bc6c3ab..817faab 100644 --- a/scripts/devstream/license_detect.py +++ b/scripts/devstream/license_detect.py @@ -42,6 +42,21 @@ def match(name): ("good, not evil", "JSON License"), ] +# Restrictions people tack onto a standard license text ("MIT, but you may not use this commercially"). +# Kept to wording that restricts; plenty of OSI texts talk about commercial use without limiting it. +_MAY_NOT = r"\b(?:(?:may|must|shall|can|will)(?: not|not| never)|can't|cannot|won't|mustn't|shan't)" +_USE = r"(?:use|used|usage|purposes?|projects?|products?)" +RESTRICTION_RE = re.compile("|".join([ + rf"{_MAY_NOT} (?:be )?(?:used?|sold|sell|resold|resell|redistributed?|distributed?)\b[^.;]{{0,40}}\bcommercial", + rf"{_MAY_NOT} (?:be )?(?:sold|sell|resold|resell)\b", + r"\bcommercial (?:use|usage|purposes?|distribution|exploitation)\b[^.;]{0,40}\b(?:is|are) " + r"(?:not (?:permitted|allowed)|prohibited|forbidden)", + r"\b(?:no|without) commercial (?:use|usage|purposes?)\b", + rf"\b(?:personal|private|non-?commercial|educational|academic) {_USE} only\b", + rf"\bonly (?:for|be used for|be used in) (?:personal|private|non-?commercial|educational|academic) {_USE}", + r"\bcommercial (?:use|usage|purposes?)\b[^.;]{0,40}\brequires?\b", +])) + # (SPDX ID, phrases that must all appear, phrases that must not). The first phrase is the # license's opening, the rest are standard text from deeper in the same license, so a # look-alike that borrows only the opening doesn't match. First match wins, so more @@ -217,8 +232,20 @@ def _spdx_scan(text: str, allowed: frozenset = frozenset()) -> tuple[str | None, return found, bad +def _restricted(text: str) -> bool: + return bool(RESTRICTION_RE.search(_norm(text).replace("\u2019", "'"))) + + def _detect_text(text: str, allowed: frozenset = frozenset()) -> tuple[str | None, str | None]: """(osi_id, non_osi_name) for one license file.""" + found, bad = _detect_known(text, allowed) + if found and _restricted(text): + # A fixed name, never the file's own words: this reason is posted publicly. + return None, f"{found} with an added restriction" + return found, bad + + +def _detect_known(text: str, allowed: frozenset = frozenset()) -> tuple[str | None, str | None]: bad = _non_osi(text) if bad: return None, bad @@ -260,6 +287,8 @@ def _readme_license(readme: str, allowed: frozenset = frozenset()) -> tuple[str m = NAME_RE.search(low) if m and not NEGATION_RE.search(low) and not NC_ND.intersection(re.findall(r"[a-z0-9]+", low)) \ and _id_ok(NAMES[m.group(1)], allowed): + if _restricted(section): + return None, f"{NAMES[m.group(1)]} with an added restriction" return NAMES[m.group(1)], None return None, None diff --git a/scripts/tests/test_license_detect.py b/scripts/tests/test_license_detect.py index d821593..df56c25 100644 --- a/scripts/tests/test_license_detect.py +++ b/scripts/tests/test_license_detect.py @@ -60,6 +60,27 @@ def test_spdx_and_needs_all(self): g = lic_gh({"LICENSE": "SPDX-License-Identifier: MIT AND Proprietary"}) self.assertIn("isn't an open-source license", run(g).failures[0]) + def test_added_restriction_after_a_license_text_fails(self): + msg = MSG_NON_OSI.format("MIT with an added restriction") + canonical = (FIXTURES / "MIT.txt").read_text() + for extra in ("You may not use this commercially.", "This software may not be sold.", + "Commercial use is prohibited.", "For personal use only.", + "Commercial use requires a paid license from the author.", + "You can\u2019t sell this software.", "It can only be used for non-commercial projects."): + with self.subTest(extra): + self.assertEqual(run(lic_gh({"LICENSE": canonical + "\n\n" + extra})).failures, [msg]) + g = lic_gh({"LICENSE": "SPDX-License-Identifier: MIT\nNo commercial use."}) + self.assertEqual(run(g).failures, [msg]) + g = lic_gh({}, readme=README + "\n## License\n\nMIT\n\nFor personal use only.\n") + self.assertEqual(run(g).failures, [msg]) + + def test_canonical_texts_carry_no_restriction(self): + from scripts.devstream.license_detect import _restricted + for f in sorted(FIXTURES.glob("*.txt")): + with self.subTest(f.name): + # CC BY-NC is the one text that really does restrict commercial use. + self.assertEqual(_restricted(f.read_text()), f.name == "CC-BY-NC-4.0.txt") + def test_sspl_rejected_by_name(self): r = run(lic_gh({"LICENSE": SSPL + MIT})) self.assertEqual( From 4557a1099e035edd2524f0ab48c00a0cb2c3fe1a Mon Sep 17 00:00:00 2001 From: Foothills Digital Date: Fri, 6 Nov 2026 10:15:24 -0700 Subject: [PATCH 2/2] fix(submit): skip lifted limits and trademark notices in the restriction check --- scripts/devstream/license_detect.py | 20 +++++++++++++++++--- scripts/tests/test_license_detect.py | 24 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/scripts/devstream/license_detect.py b/scripts/devstream/license_detect.py index 817faab..3541e3c 100644 --- a/scripts/devstream/license_detect.py +++ b/scripts/devstream/license_detect.py @@ -46,15 +46,19 @@ def match(name): # Kept to wording that restricts; plenty of OSI texts talk about commercial use without limiting it. _MAY_NOT = r"\b(?:(?:may|must|shall|can|will)(?: not|not| never)|can't|cannot|won't|mustn't|shan't)" _USE = r"(?:use|used|usage|purposes?|projects?|products?)" +# "No commercial use restrictions" lifts a limit rather than adding one. +_NOT_A_LIMIT = r"(?![^.;]{0,30}?\b(?:restrictions?|limits?|limitations?|fees?)\b)" RESTRICTION_RE = re.compile("|".join([ rf"{_MAY_NOT} (?:be )?(?:used?|sold|sell|resold|resell|redistributed?|distributed?)\b[^.;]{{0,40}}\bcommercial", rf"{_MAY_NOT} (?:be )?(?:sold|sell|resold|resell)\b", r"\bcommercial (?:use|usage|purposes?|distribution|exploitation)\b[^.;]{0,40}\b(?:is|are) " r"(?:not (?:permitted|allowed)|prohibited|forbidden)", - r"\b(?:no|without) commercial (?:use|usage|purposes?)\b", + rf"\b(?:no|without) commercial (?:use|usage|purposes?)\b{_NOT_A_LIMIT}", rf"\b(?:personal|private|non-?commercial|educational|academic) {_USE} only\b", rf"\bonly (?:for|be used for|be used in) (?:personal|private|non-?commercial|educational|academic) {_USE}", - r"\bcommercial (?:use|usage|purposes?)\b[^.;]{0,40}\brequires?\b", + # ...unless all it requires is the attribution or notice the license already asks for. + rf"\bcommercial (?:use|usage|purposes?)\b[^.;]{{0,40}}\brequires?\b{_NOT_A_LIMIT}" + r"(?![^.;]{0,40}?\b(?:attribution|notice|credit)\b)", ])) # (SPDX ID, phrases that must all appear, phrases that must not). The first phrase is the @@ -232,8 +236,18 @@ def _spdx_scan(text: str, allowed: frozenset = frozenset()) -> tuple[str | None, return found, bad +# A limit on using someone's trademark (MIT's Kerberos notice, bundled in MySQL's LICENSE) isn't a license term. +TRADEMARK_RE = re.compile(r"\btrade ?marks?\b|\btrade names?\b|\bservice marks?\b|\blogos?\b") + + def _restricted(text: str) -> bool: - return bool(RESTRICTION_RE.search(_norm(text).replace("\u2019", "'"))) + t = _norm(text).replace("\u2019", "'") + for m in RESTRICTION_RE.finditer(t): + start = max(t.rfind(".", 0, m.start()), t.rfind(";", 0, m.start())) + 1 + end = min((i for i in (t.find(".", m.end()), t.find(";", m.end())) if i != -1), default=len(t)) + if not TRADEMARK_RE.search(t[start:end]): + return True + return False def _detect_text(text: str, allowed: frozenset = frozenset()) -> tuple[str | None, str | None]: diff --git a/scripts/tests/test_license_detect.py b/scripts/tests/test_license_detect.py index df56c25..4a7d63c 100644 --- a/scripts/tests/test_license_detect.py +++ b/scripts/tests/test_license_detect.py @@ -74,6 +74,30 @@ def test_added_restriction_after_a_license_text_fails(self): g = lic_gh({}, readme=README + "\n## License\n\nMIT\n\nFor personal use only.\n") self.assertEqual(run(g).failures, [msg]) + def test_readme_prose_that_lifts_a_limit_is_not_a_restriction(self): + for prose in ("There are no commercial use restrictions.", "No commercial use limits apply.", + "Without commercial use fees of any kind.", + "Commercial use requires nothing more than the notice.", + "Commercial use requires attribution, like any other use.", + "Commercial use requires no fee or other limitation."): + with self.subTest(prose): + g = lic_gh({}, readme=README + f"\n## License\n\nMIT\n\n{prose}\n") + self.assertEqual(run(g).failures, []) + for prose in ("No commercial use.", "Commercial use requires a paid license."): + with self.subTest(prose): + g = lic_gh({}, readme=README + f"\n## License\n\nMIT\n\n{prose}\n") + self.assertEqual(run(g).failures, [MSG_NON_OSI.format("MIT with an added restriction")]) + + def test_trademark_notice_is_not_a_restriction(self): + # From the MIT Kerberos notice bundled in mysql/mysql-server's LICENSE. + notice = ("Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira, and Zephyr are " + "trademarks of the Massachusetts Institute of Technology (MIT). No commercial use of these " + "trademarks may be made without prior written permission of MIT.") + canonical = (FIXTURES / "MIT.txt").read_text() + self.passes(lic_gh({"LICENSE": canonical + "\n\n" + notice})) + g = lic_gh({"LICENSE": canonical + "\n\n" + notice + " No commercial use."}) + self.assertEqual(run(g).failures, [MSG_NON_OSI.format("MIT with an added restriction")]) + def test_canonical_texts_carry_no_restriction(self): from scripts.devstream.license_detect import _restricted for f in sorted(FIXTURES.glob("*.txt")):