forgeguard 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,184 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ Copyright 2026 Gexiro Global Enterprises Ltd.
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction, and
12
+ distribution as defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
15
+ owner that is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all other entities
18
+ that control, are controlled by, or are under common control with that entity.
19
+ For the purposes of this definition, "control" means (i) the power, direct or
20
+ indirect, to cause the direction or management of such entity, whether by
21
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
25
+ permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications, including
28
+ but not limited to software source code, documentation source, and configuration
29
+ files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical transformation or
32
+ translation of a Source form, including but not limited to compiled object code,
33
+ generated documentation, and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or Object form,
36
+ made available under the License, as indicated by a copyright notice that is
37
+ included in or attached to the work.
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
40
+ is based on (or derived from) the Work and for which the editorial revisions,
41
+ annotations, elaborations, or other modifications represent, as a whole, an
42
+ original work of authorship. For the purposes of this License, Derivative Works
43
+ shall not include works that remain separable from, or merely link (or bind by
44
+ name) to the interfaces of, the Work and Derivative Works thereof.
45
+
46
+ "Contribution" shall mean any work of authorship, including the original version
47
+ of the Work and any modifications or additions to that Work or Derivative Works
48
+ thereof, that is intentionally submitted to Licensor for inclusion in the Work
49
+ by the copyright owner or by an individual or Legal Entity authorized to submit
50
+ on behalf of the copyright owner. For the purposes of this definition,
51
+ "submitted" means any form of electronic, verbal, or written communication sent
52
+ to the Licensor or its representatives, including but not limited to
53
+ communication on electronic mailing lists, source code control systems, and
54
+ issue tracking systems that are managed by, or on behalf of, the Licensor for
55
+ the purpose of discussing and improving the Work, but excluding communication
56
+ that is conspicuously marked or otherwise designated in writing by the copyright
57
+ owner as "Not a Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
60
+ of whom a Contribution has been received by Licensor and subsequently
61
+ incorporated within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
64
+ License, each Contributor hereby grants to You a perpetual, worldwide,
65
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
66
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
67
+ sublicense, and distribute the Work and such Derivative Works in Source or
68
+ Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of this License,
71
+ each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
72
+ no-charge, royalty-free, irrevocable (except as stated in this section) patent
73
+ license to make, have made, use, offer to sell, sell, import, and otherwise
74
+ transfer the Work, where such license applies only to those patent claims
75
+ licensable by such Contributor that are necessarily infringed by their
76
+ Contribution(s) alone or by combination of their Contribution(s) with the Work
77
+ to which such Contribution(s) was submitted. If You institute patent litigation
78
+ against any entity (including a cross-claim or counterclaim in a lawsuit)
79
+ alleging that the Work or a Contribution incorporated within the Work
80
+ constitutes direct or contributory patent infringement, then any patent licenses
81
+ granted to You under this License for that Work shall terminate as of the date
82
+ such litigation is filed.
83
+
84
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
85
+ Derivative Works thereof in any medium, with or without modifications, and in
86
+ Source or Object form, provided that You meet the following conditions:
87
+
88
+ (a) You must give any other recipients of the Work or Derivative Works a copy of
89
+ this License; and
90
+
91
+ (b) You must cause any modified files to carry prominent notices stating that
92
+ You changed the files; and
93
+
94
+ (c) You must retain, in the Source form of any Derivative Works that You
95
+ distribute, all copyright, patent, trademark, and attribution notices from the
96
+ Source form of the Work, excluding those notices that do not pertain to any part
97
+ of the Derivative Works; and
98
+
99
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then
100
+ any Derivative Works that You distribute must include a readable copy of the
101
+ attribution notices contained within such NOTICE file, excluding those notices
102
+ that do not pertain to any part of the Derivative Works, in at least one of the
103
+ following places: within a NOTICE text file distributed as part of the
104
+ Derivative Works; within the Source form or documentation, if provided along
105
+ with the Derivative Works; or, within a display generated by the Derivative
106
+ Works, if and wherever such third-party notices normally appear. The contents of
107
+ the NOTICE file are for informational purposes only and do not modify the
108
+ License. You may add Your own attribution notices within Derivative Works that
109
+ You distribute, alongside or as an addendum to the NOTICE text from the Work,
110
+ provided that such additional attribution notices cannot be construed as
111
+ modifying the License.
112
+
113
+ You may add Your own copyright statement to Your modifications and may provide
114
+ additional or different license terms and conditions for use, reproduction, or
115
+ distribution of Your modifications, or for any such Derivative Works as a whole,
116
+ provided Your use, reproduction, and distribution of the Work otherwise complies
117
+ with the conditions stated in this License.
118
+
119
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
120
+ Contribution intentionally submitted for inclusion in the Work by You to the
121
+ Licensor shall be under the terms and conditions of this License, without any
122
+ additional terms or conditions. Notwithstanding the above, nothing herein shall
123
+ supersede or modify the terms of any separate license agreement you may have
124
+ executed with Licensor regarding such Contributions.
125
+
126
+ 6. Trademarks. This License does not grant permission to use the trade names,
127
+ trademarks, service marks, or product names of the Licensor, except as required
128
+ for reasonable and customary use in describing the origin of the Work and
129
+ reproducing the content of the NOTICE file.
130
+
131
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
132
+ writing, Licensor provides the Work (and each Contributor provides its
133
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
134
+ KIND, either express or implied, including, without limitation, any warranties or
135
+ conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
136
+ PARTICULAR PURPOSE. You are solely responsible for determining the
137
+ appropriateness of using or redistributing the Work and assume any risks
138
+ associated with Your exercise of permissions under this License.
139
+
140
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
141
+ tort (including negligence), contract, or otherwise, unless required by
142
+ applicable law (such as deliberate and grossly negligent acts) or agreed to in
143
+ writing, shall any Contributor be liable to You for damages, including any
144
+ direct, indirect, special, incidental, or consequential damages of any character
145
+ arising as a result of this License or out of the use or inability to use the
146
+ Work (including but not limited to damages for loss of goodwill, work stoppage,
147
+ computer failure or malfunction, or any and all other commercial damages or
148
+ losses), even if such Contributor has been advised of the possibility of such
149
+ damages.
150
+
151
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or
152
+ Derivative Works thereof, You may choose to offer, and charge a fee for,
153
+ acceptance of support, warranty, indemnity, or other liability obligations
154
+ and/or rights consistent with this License. However, in accepting such
155
+ obligations, You may act only on Your own behalf and on Your sole
156
+ responsibility, not on behalf of any other Contributor, and only if You agree to
157
+ indemnify, defend, and hold each Contributor harmless for any liability incurred
158
+ by, or claims asserted against, such Contributor by reason of your accepting any
159
+ such warranty or additional liability.
160
+
161
+ END OF TERMS AND CONDITIONS
162
+
163
+ APPENDIX: How to apply the Apache License to your work.
164
+
165
+ To apply the Apache License to your work, attach the following boilerplate
166
+ notice, with the fields enclosed by brackets "[]" replaced with your own
167
+ identifying information. Do not include the brackets. The text should be
168
+ enclosed in the appropriate comment syntax for the file format. We also
169
+ recommend that a file or class name and description of purpose be included on
170
+ the same "printed page" as the copyright notice for easier identification within
171
+ third-party archives.
172
+
173
+ Copyright 2026 Gexiro Global Enterprises Ltd.
174
+
175
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
176
+ this file except in compliance with the License. You may obtain a copy of the
177
+ License at
178
+
179
+ http://www.apache.org/licenses/LICENSE-2.0
180
+
181
+ Unless required by applicable law or agreed to in writing, software distributed
182
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
183
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
184
+ specific language governing permissions and limitations under the License.
@@ -0,0 +1,135 @@
1
+ Metadata-Version: 2.4
2
+ Name: forgeguard
3
+ Version: 0.2.0
4
+ Summary: Read-only security posture self-check for self-hosted Gitea and Forgejo.
5
+ Author: Gexiro Global Enterprises Ltd
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/gexiro-global/forgeguard
8
+ Project-URL: Repository, https://github.com/gexiro-global/forgeguard
9
+ Keywords: gitea,forgejo,security,posture,self-hosted,cve-2026-27771
10
+ Requires-Python: >=3.11
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: httpx>=0.27
14
+ Requires-Dist: pydantic>=2
15
+ Requires-Dist: typer>=0.12
16
+ Provides-Extra: dev
17
+ Requires-Dist: pytest>=8; extra == "dev"
18
+ Requires-Dist: build>=1; extra == "dev"
19
+ Dynamic: license-file
20
+
21
+ <!-- Badges placeholder: CI, package version, license -->
22
+
23
+ # ForgeGuard by Gexiro
24
+
25
+ Read-only security posture self-check for self-hosted Gitea and Forgejo.
26
+
27
+ ForgeGuard helps operators of self-hosted Gitea/Forgejo instances understand patch currency, registry exposure, anonymous access posture, and basic security configuration without exploit probes or internet-wide scanning. It is intended to close a visibility gap after self-hosting: operators need quick, repeatable evidence about whether one authorized forge is patched and whether anonymous surfaces look intentionally constrained.
28
+
29
+ ## What It Checks In v0.2
30
+
31
+ - Forge version and patch currency against the fixed Gitea 1.26.2 release for CVE-2026-27771.
32
+ - CVE-2026-27771 posture using safe root response inference.
33
+ - Anonymous registry posture via safe `/v2/` response inference.
34
+ - Sign-in and anonymous access posture.
35
+ - Basic registry exposure.
36
+
37
+ ## What It Does NOT Do
38
+
39
+ - No mass scanning.
40
+ - No exploit PoC.
41
+ - No private blob or manifest retrieval.
42
+ - No unauthenticated third-party probing.
43
+ - No AI code review.
44
+ - No guarantee of full security.
45
+
46
+ ## Install
47
+
48
+ > A PyPI release is coming soon. Until then, install the latest from source:
49
+
50
+ ```bash
51
+ python -m pip install "git+https://github.com/gexiro-global/forgeguard.git"
52
+ ```
53
+
54
+ Once published to PyPI:
55
+
56
+ ```bash
57
+ python -m pip install forgeguard
58
+ ```
59
+
60
+ For local development:
61
+
62
+ ```bash
63
+ git clone https://github.com/gexiro-global/forgeguard.git
64
+ cd forgeguard
65
+ python -m pip install -e ".[dev]"
66
+ ```
67
+
68
+ ## Quickstart
69
+
70
+ ```bash
71
+ forgeguard scan --url https://git.example.com --authorized --out ./reports/scan_report.md
72
+ ```
73
+
74
+ Use `--known-version` when your version endpoint is intentionally hidden:
75
+
76
+ ```bash
77
+ forgeguard scan --url https://git.example.com --authorized --known-version 1.26.2 --format md,json --out ./reports/scan_report.md
78
+ ```
79
+
80
+ ## Sample Output
81
+
82
+ A before/after on a synthetic instance, showing the CVE-2026-27771 patch-currency gap closing after a Gitea update.
83
+
84
+ **Before** - Gitea `1.25.3` (mitigated, but the code-level fix is missing):
85
+
86
+ ```text
87
+ # ForgeGuard by Gexiro - https://git.example.com
88
+ Forge: gitea 1.25.3 | Score: 66/100 (C)
89
+ Summary: critical 1 | high 1 | medium 0 | low 0 | pass 3
90
+ Top action: P1 - Update Gitea to >=1.26.2
91
+ (CVE-2026-27771 window present, mitigation active, code-level fix missing)
92
+ ```
93
+
94
+ **After** - Gitea `1.26.2` (patched):
95
+
96
+ ```text
97
+ # ForgeGuard by Gexiro - https://git.example.com
98
+ Forge: gitea 1.26.2 | Score: 100/100 (A)
99
+ Summary: critical 0 | high 0 | medium 0 | low 0 | pass 5
100
+ Top action: None - all checks pass.
101
+ ```
102
+
103
+ | Finding | Before (1.25.3) | After (1.26.2) |
104
+ |---|---|---|
105
+ | FG-VER - patch currency | FAIL / HIGH | **PASS** |
106
+ | FG-CVE-27771 - exposure posture | WARN / CRITICAL (mitigated) | **PASS** |
107
+ | FG-SIGNIN / FG-REG / FG-ANON | PASS | PASS |
108
+ | **Score** | **66/100 (C)** | **100/100 (A)** |
109
+
110
+ The update closes the code-level patch-currency gap; the posture checks were already passing. Full synthetic reports: [`examples/scan_report_mitigated_pre_update.md`](examples/scan_report_mitigated_pre_update.md) and [`examples/scan_report_patched_post_update.md`](examples/scan_report_patched_post_update.md).
111
+
112
+ ## Scoring
113
+
114
+ ForgeGuard scoring is deterministic and does not use AI. Findings subtract fixed penalties from 100: critical -40, high -20, medium -10, low -4. Warning findings use `WARN_FACTOR = 0.35`, so a critical warning subtracts 14 points. Grades are A at 90+, B at 75+, C at 60+, D at 40+, and F below 40.
115
+
116
+ ## Security And Ethics
117
+
118
+ Run ForgeGuard only on instances you own or are explicitly authorized to assess. ForgeGuard v0.2 uses read-only HTTP GET checks and stops at posture signals; it does not request package contents or registry artifacts. Reports are posture evidence, not proof of compromise.
119
+
120
+ See `AUTHORIZED_USE.md` and `SECURITY.md`.
121
+
122
+ ## Roadmap
123
+
124
+ - v0.3: runner, token, and TLS posture checks.
125
+ - v0.4: optional issue emitter and AI remediation notes.
126
+ - v1: supply-chain, SBOM, and OSV enrichment.
127
+ - Later: semantic code intelligence.
128
+
129
+ ## Responsible Disclosure
130
+
131
+ To report a vulnerability in ForgeGuard itself, see `SECURITY.md`.
132
+
133
+ ForgeGuard by Gexiro
134
+
135
+ Not affiliated with Gitea, Forgejo, Codeberg, GitHub, or GitLab.
@@ -0,0 +1,115 @@
1
+ <!-- Badges placeholder: CI, package version, license -->
2
+
3
+ # ForgeGuard by Gexiro
4
+
5
+ Read-only security posture self-check for self-hosted Gitea and Forgejo.
6
+
7
+ ForgeGuard helps operators of self-hosted Gitea/Forgejo instances understand patch currency, registry exposure, anonymous access posture, and basic security configuration without exploit probes or internet-wide scanning. It is intended to close a visibility gap after self-hosting: operators need quick, repeatable evidence about whether one authorized forge is patched and whether anonymous surfaces look intentionally constrained.
8
+
9
+ ## What It Checks In v0.2
10
+
11
+ - Forge version and patch currency against the fixed Gitea 1.26.2 release for CVE-2026-27771.
12
+ - CVE-2026-27771 posture using safe root response inference.
13
+ - Anonymous registry posture via safe `/v2/` response inference.
14
+ - Sign-in and anonymous access posture.
15
+ - Basic registry exposure.
16
+
17
+ ## What It Does NOT Do
18
+
19
+ - No mass scanning.
20
+ - No exploit PoC.
21
+ - No private blob or manifest retrieval.
22
+ - No unauthenticated third-party probing.
23
+ - No AI code review.
24
+ - No guarantee of full security.
25
+
26
+ ## Install
27
+
28
+ > A PyPI release is coming soon. Until then, install the latest from source:
29
+
30
+ ```bash
31
+ python -m pip install "git+https://github.com/gexiro-global/forgeguard.git"
32
+ ```
33
+
34
+ Once published to PyPI:
35
+
36
+ ```bash
37
+ python -m pip install forgeguard
38
+ ```
39
+
40
+ For local development:
41
+
42
+ ```bash
43
+ git clone https://github.com/gexiro-global/forgeguard.git
44
+ cd forgeguard
45
+ python -m pip install -e ".[dev]"
46
+ ```
47
+
48
+ ## Quickstart
49
+
50
+ ```bash
51
+ forgeguard scan --url https://git.example.com --authorized --out ./reports/scan_report.md
52
+ ```
53
+
54
+ Use `--known-version` when your version endpoint is intentionally hidden:
55
+
56
+ ```bash
57
+ forgeguard scan --url https://git.example.com --authorized --known-version 1.26.2 --format md,json --out ./reports/scan_report.md
58
+ ```
59
+
60
+ ## Sample Output
61
+
62
+ A before/after on a synthetic instance, showing the CVE-2026-27771 patch-currency gap closing after a Gitea update.
63
+
64
+ **Before** - Gitea `1.25.3` (mitigated, but the code-level fix is missing):
65
+
66
+ ```text
67
+ # ForgeGuard by Gexiro - https://git.example.com
68
+ Forge: gitea 1.25.3 | Score: 66/100 (C)
69
+ Summary: critical 1 | high 1 | medium 0 | low 0 | pass 3
70
+ Top action: P1 - Update Gitea to >=1.26.2
71
+ (CVE-2026-27771 window present, mitigation active, code-level fix missing)
72
+ ```
73
+
74
+ **After** - Gitea `1.26.2` (patched):
75
+
76
+ ```text
77
+ # ForgeGuard by Gexiro - https://git.example.com
78
+ Forge: gitea 1.26.2 | Score: 100/100 (A)
79
+ Summary: critical 0 | high 0 | medium 0 | low 0 | pass 5
80
+ Top action: None - all checks pass.
81
+ ```
82
+
83
+ | Finding | Before (1.25.3) | After (1.26.2) |
84
+ |---|---|---|
85
+ | FG-VER - patch currency | FAIL / HIGH | **PASS** |
86
+ | FG-CVE-27771 - exposure posture | WARN / CRITICAL (mitigated) | **PASS** |
87
+ | FG-SIGNIN / FG-REG / FG-ANON | PASS | PASS |
88
+ | **Score** | **66/100 (C)** | **100/100 (A)** |
89
+
90
+ The update closes the code-level patch-currency gap; the posture checks were already passing. Full synthetic reports: [`examples/scan_report_mitigated_pre_update.md`](examples/scan_report_mitigated_pre_update.md) and [`examples/scan_report_patched_post_update.md`](examples/scan_report_patched_post_update.md).
91
+
92
+ ## Scoring
93
+
94
+ ForgeGuard scoring is deterministic and does not use AI. Findings subtract fixed penalties from 100: critical -40, high -20, medium -10, low -4. Warning findings use `WARN_FACTOR = 0.35`, so a critical warning subtracts 14 points. Grades are A at 90+, B at 75+, C at 60+, D at 40+, and F below 40.
95
+
96
+ ## Security And Ethics
97
+
98
+ Run ForgeGuard only on instances you own or are explicitly authorized to assess. ForgeGuard v0.2 uses read-only HTTP GET checks and stops at posture signals; it does not request package contents or registry artifacts. Reports are posture evidence, not proof of compromise.
99
+
100
+ See `AUTHORIZED_USE.md` and `SECURITY.md`.
101
+
102
+ ## Roadmap
103
+
104
+ - v0.3: runner, token, and TLS posture checks.
105
+ - v0.4: optional issue emitter and AI remediation notes.
106
+ - v1: supply-chain, SBOM, and OSV enrichment.
107
+ - Later: semantic code intelligence.
108
+
109
+ ## Responsible Disclosure
110
+
111
+ To report a vulnerability in ForgeGuard itself, see `SECURITY.md`.
112
+
113
+ ForgeGuard by Gexiro
114
+
115
+ Not affiliated with Gitea, Forgejo, Codeberg, GitHub, or GitLab.
@@ -0,0 +1,7 @@
1
+ """ForgeGuard by Gexiro.
2
+
3
+ Read-only security posture and supply-chain visibility for self-hosted
4
+ Gitea/Forgejo. Scope is limited to own or explicitly authorized instances.
5
+ """
6
+
7
+ __version__ = "0.2.0"
@@ -0,0 +1,4 @@
1
+ from .cli import app
2
+
3
+ if __name__ == "__main__":
4
+ app()
@@ -0,0 +1,172 @@
1
+ from __future__ import annotations
2
+
3
+ import re
4
+
5
+ from .client import ForgeClient
6
+ from .models import Finding, Severity, Status, Target
7
+ from .safety import SAFE_GET_PATHS
8
+
9
+ FIXED_VERSION = "1.26.2"
10
+ # Back-compat alias; the canonical read-only allowlist lives in forgeguard.safety.
11
+ SAFE_ANON_PATHS = SAFE_GET_PATHS
12
+
13
+
14
+ def _semver(version: str | None) -> tuple[int, int, int] | None:
15
+ match = re.match(r"(\d+)\.(\d+)\.(\d+)", version or "")
16
+ return tuple(int(part) for part in match.groups()) if match else None # type: ignore[return-value]
17
+
18
+
19
+ def _is_vulnerable(version: str | None) -> bool | None:
20
+ parsed, fixed = _semver(version), _semver(FIXED_VERSION)
21
+ return None if parsed is None else parsed < fixed
22
+
23
+
24
+ async def _detect(client: ForgeClient, known_version: str | None) -> tuple[Target, bool]:
25
+ target = Target(url=client.base, forge="unknown", version=known_version)
26
+ anon_disclosed = False
27
+ response = await client.get("/api/v1/version", auth=client.has_token)
28
+ if response is not None and response.status_code == 200:
29
+ try:
30
+ target.version = response.json().get("version", target.version)
31
+ except Exception: # noqa: BLE001 - tolerate non-JSON server responses
32
+ pass
33
+ if not client.has_token:
34
+ anon_disclosed = True
35
+ if target.version:
36
+ target.forge = "gitea"
37
+ return target, anon_disclosed
38
+
39
+
40
+ async def check_version(client: ForgeClient, target: Target, anon_disclosed: bool) -> list[Finding]:
41
+ findings: list[Finding] = []
42
+ vulnerable_version = _is_vulnerable(target.version)
43
+ if target.version is None:
44
+ findings.append(Finding(id="FG-VER", title="Forge version undetermined", severity=Severity.medium,
45
+ status=Status.INFO, evidence={"version": None},
46
+ rationale="Version is not available from the safe API path and no local version was supplied.",
47
+ remediation="Re-run with --token or --known-version to enable patch-currency checks."))
48
+ elif vulnerable_version:
49
+ findings.append(Finding(id="FG-VER", title="Vulnerable version: patch-currency gap",
50
+ severity=Severity.high, status=Status.FAIL,
51
+ evidence={"version": target.version, "fixed_in": FIXED_VERSION},
52
+ rationale=f"Running {target.version} < {FIXED_VERSION}: the code-level fix for CVE-2026-27771 is missing.",
53
+ remediation=f"Update Gitea to >= {FIXED_VERSION}.", references=["CVE-2026-27771"]))
54
+ else:
55
+ findings.append(Finding(id="FG-VER", title="Patched: version is at or above the fixed release",
56
+ severity=Severity.info, status=Status.PASS,
57
+ evidence={"version": target.version, "fixed_in": FIXED_VERSION},
58
+ rationale=f"Running {target.version} (>= {FIXED_VERSION})."))
59
+ if anon_disclosed:
60
+ findings.append(Finding(id="FG-VER-DISCLOSE", title="Version disclosed to anonymous users",
61
+ severity=Severity.low, status=Status.WARN,
62
+ evidence={"endpoint": "/api/v1/version"},
63
+ rationale="Exact version is readable without authentication, which increases targeting context.",
64
+ remediation="Set REQUIRE_SIGNIN_VIEW=true to hide metadata from anonymous users."))
65
+ return findings
66
+
67
+
68
+ async def check_cve_27771(client: ForgeClient, target: Target) -> list[Finding]:
69
+ vulnerable_version = _is_vulnerable(target.version)
70
+ v2_response = await client.get("/v2/")
71
+ anon_v2 = v2_response.status_code if v2_response is not None else None
72
+ home_response = await client.get("/")
73
+ home = home_response.status_code if home_response is not None else None
74
+ signin_required = (home in (401, 403)) or (anon_v2 in (401, 403))
75
+ registry_anon_open = anon_v2 == 200
76
+ evidence = {
77
+ "version": target.version,
78
+ "anon_v2_http": anon_v2,
79
+ "signin_required_inferred": signin_required,
80
+ "registry_anon_open": registry_anon_open,
81
+ }
82
+ # State-dependent remediation: a patched instance carries no update action.
83
+ if vulnerable_version is False:
84
+ status, severity, rationale, remediation = (
85
+ Status.PASS,
86
+ Severity.info,
87
+ f"Patched: {target.version} is at or above {FIXED_VERSION}.",
88
+ "",
89
+ )
90
+ elif vulnerable_version is None:
91
+ status, severity, rationale, remediation = (
92
+ Status.INFO,
93
+ Severity.medium,
94
+ "Version unknown; CVE-2026-27771 exposure posture cannot be assessed.",
95
+ "Re-run with --token or --known-version to assess patch currency.",
96
+ )
97
+ elif registry_anon_open and not signin_required:
98
+ status, severity, rationale, remediation = (
99
+ Status.FAIL,
100
+ Severity.critical,
101
+ "Active exposure: vulnerable version plus anonymous /v2/ access and no sign-in enforcement signal.",
102
+ f"Update Gitea to >= {FIXED_VERSION} immediately and enforce authenticated registry access.",
103
+ )
104
+ else:
105
+ status, severity, rationale, remediation = (
106
+ Status.WARN,
107
+ Severity.critical,
108
+ "Mitigated posture: vulnerable version remains, but anonymous /v2/ access is denied or sign-in is enforced.",
109
+ f"Update Gitea to >= {FIXED_VERSION}; keep sign-in enforcement until patched.",
110
+ )
111
+ return [Finding(id="FG-CVE-27771", title="CVE-2026-27771 exposure posture",
112
+ severity=severity, status=status, evidence=evidence, rationale=rationale,
113
+ remediation=remediation,
114
+ references=["CVE-2026-27771", "https://blog.gitea.com/release-of-1.26.2/"], cwe="CWE-285")]
115
+
116
+
117
+ async def check_signin(client: ForgeClient, target: Target) -> list[Finding]:
118
+ api_response = await client.get("/api/v1/repos/search?limit=1")
119
+ anon_api = api_response.status_code if api_response is not None else None
120
+ browse_response = await client.get("/explore/repos")
121
+ anon_browse = browse_response.status_code if browse_response is not None else None
122
+ required = anon_api in (401, 403) and anon_browse in (401, 403, 301, 302, 303)
123
+ if required:
124
+ return [Finding(id="FG-SIGNIN", title="Anonymous access requires sign-in", severity=Severity.info,
125
+ status=Status.PASS, evidence={"anon_api": anon_api, "anon_explore": anon_browse},
126
+ rationale="REQUIRE_SIGNIN_VIEW appears enforced; anonymous browsing/API access is denied.")]
127
+ return [Finding(id="FG-SIGNIN", title="Anonymous browsing/API is open", severity=Severity.medium,
128
+ status=Status.WARN, evidence={"anon_api": anon_api, "anon_explore": anon_browse},
129
+ rationale="Anonymous users can read repository/API surface.",
130
+ remediation="Set REQUIRE_SIGNIN_VIEW=true if this is a private forge.")]
131
+
132
+
133
+ async def check_registry(client: ForgeClient, target: Target) -> list[Finding]:
134
+ response = await client.get("/v2/")
135
+ anon_v2 = response.status_code if response is not None else None
136
+ if anon_v2 == 200:
137
+ return [Finding(id="FG-REG", title="Container registry reachable anonymously", severity=Severity.high,
138
+ status=Status.WARN, evidence={"anon_v2_http": anon_v2},
139
+ rationale="OCI /v2/ root responds to anonymous clients.",
140
+ remediation="Require authentication for the registry; update past CVE-2026-27771.",
141
+ references=["CVE-2026-27771"])]
142
+ return [Finding(id="FG-REG", title="Container registry not anonymously reachable", severity=Severity.info,
143
+ status=Status.PASS, evidence={"anon_v2_http": anon_v2},
144
+ rationale="Anonymous /v2/ access is denied.")]
145
+
146
+
147
+ async def check_anon(client: ForgeClient, target: Target) -> list[Finding]:
148
+ paths = ["/api/v1/repos/search?limit=1", "/explore/repos", "/api/v1/users/search?limit=1"]
149
+ open_surfaces = []
150
+ for path in paths:
151
+ response = await client.get(path)
152
+ if response is not None and response.status_code == 200:
153
+ open_surfaces.append(path)
154
+ if open_surfaces:
155
+ return [Finding(id="FG-ANON", title="Anonymously readable surfaces", severity=Severity.medium,
156
+ status=Status.WARN, evidence={"open": open_surfaces},
157
+ rationale="These endpoints return data without authentication.",
158
+ remediation="Enable REQUIRE_SIGNIN_VIEW or restrict visibility.")]
159
+ return [Finding(id="FG-ANON", title="No anonymously readable surfaces detected", severity=Severity.info,
160
+ status=Status.PASS, evidence={"probed": paths},
161
+ rationale="Probed endpoints all require authentication.")]
162
+
163
+
164
+ async def run_all_checks(client: ForgeClient, known_version: str | None = None) -> tuple[list[Finding], Target]:
165
+ target, anon_disclosed = await _detect(client, known_version)
166
+ findings: list[Finding] = []
167
+ findings += await check_version(client, target, anon_disclosed)
168
+ findings += await check_cve_27771(client, target)
169
+ findings += await check_signin(client, target)
170
+ findings += await check_registry(client, target)
171
+ findings += await check_anon(client, target)
172
+ return findings, target