visual-access-contract 0.2.1__tar.gz → 0.3.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.
- visual_access_contract-0.3.0/MANIFEST.in +6 -0
- {visual_access_contract-0.2.1/visual_access_contract.egg-info → visual_access_contract-0.3.0}/PKG-INFO +63 -12
- visual_access_contract-0.2.1/PKG-INFO → visual_access_contract-0.3.0/README.md +43 -21
- visual_access_contract-0.3.0/pyproject.toml +51 -0
- visual_access_contract-0.3.0/vac_cli/__init__.py +1 -0
- visual_access_contract-0.3.0/vac_cli/__main__.py +20 -0
- {visual_access_contract-0.2.1 → visual_access_contract-0.3.0/vac_cli}/checks/visual_check.py +1 -1
- visual_access_contract-0.3.0/vac_cli/ci_contract.py +249 -0
- {visual_access_contract-0.2.1/vac → visual_access_contract-0.3.0/vac_cli}/cli.py +4 -4
- visual_access_contract-0.3.0/vac_cli/commands.py +156 -0
- {visual_access_contract-0.2.1/vac → visual_access_contract-0.3.0/vac_cli}/contract.py +7 -7
- visual_access_contract-0.2.1/vac/demo_fixture.py → visual_access_contract-0.3.0/vac_cli/demo.py +72 -3
- {visual_access_contract-0.2.1/vac → visual_access_contract-0.3.0/vac_cli}/html_report.py +2 -2
- {visual_access_contract-0.2.1/vac → visual_access_contract-0.3.0/vac_cli}/output.py +3 -3
- visual_access_contract-0.3.0/vac_cli/platform.py +66 -0
- {visual_access_contract-0.2.1/vac → visual_access_contract-0.3.0/vac_cli}/runner.py +4 -4
- visual_access_contract-0.3.0/vac_cli/scan.py +261 -0
- {visual_access_contract-0.2.1/vac → visual_access_contract-0.3.0/vac_cli}/session.py +1 -1
- visual_access_contract-0.3.0/vac_cli/template.yaml +28 -0
- visual_access_contract-0.2.1/README.md → visual_access_contract-0.3.0/visual_access_contract.egg-info/PKG-INFO +72 -6
- visual_access_contract-0.3.0/visual_access_contract.egg-info/SOURCES.txt +29 -0
- visual_access_contract-0.3.0/visual_access_contract.egg-info/entry_points.txt +2 -0
- visual_access_contract-0.3.0/visual_access_contract.egg-info/requires.txt +10 -0
- visual_access_contract-0.3.0/visual_access_contract.egg-info/top_level.txt +1 -0
- visual_access_contract-0.2.1/pyproject.toml +0 -25
- visual_access_contract-0.2.1/tests/test_cli_adoption.py +0 -117
- visual_access_contract-0.2.1/tests/test_contract_cli.py +0 -81
- visual_access_contract-0.2.1/tests/test_demo_report.py +0 -63
- visual_access_contract-0.2.1/tests/test_integration_app.py +0 -93
- visual_access_contract-0.2.1/vac/__init__.py +0 -0
- visual_access_contract-0.2.1/vac/__main__.py +0 -40
- visual_access_contract-0.2.1/vac/demo-contract.yaml +0 -46
- visual_access_contract-0.2.1/vac/demo.py +0 -53
- visual_access_contract-0.2.1/visual_access_contract.egg-info/SOURCES.txt +0 -29
- visual_access_contract-0.2.1/visual_access_contract.egg-info/entry_points.txt +0 -2
- visual_access_contract-0.2.1/visual_access_contract.egg-info/requires.txt +0 -6
- visual_access_contract-0.2.1/visual_access_contract.egg-info/top_level.txt +0 -3
- {visual_access_contract-0.2.1 → visual_access_contract-0.3.0}/LICENSE +0 -0
- {visual_access_contract-0.2.1 → visual_access_contract-0.3.0}/setup.cfg +0 -0
- {visual_access_contract-0.2.1 → visual_access_contract-0.3.0/vac_cli}/checks/__init__.py +0 -0
- {visual_access_contract-0.2.1 → visual_access_contract-0.3.0/vac_cli}/checks/structured_check.py +0 -0
- /visual_access_contract-0.2.1/evidence/__init__.py → /visual_access_contract-0.3.0/vac_cli/py.typed +0 -0
- {visual_access_contract-0.2.1/evidence → visual_access_contract-0.3.0/vac_cli}/reporter.py +0 -0
- {visual_access_contract-0.2.1 → visual_access_contract-0.3.0}/visual_access_contract.egg-info/dependency_links.txt +0 -0
|
@@ -1,23 +1,37 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: visual-access-contract
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: CI checks for role-specific visibility of synthetic data
|
|
5
5
|
License-Expression: Apache-2.0
|
|
6
|
-
|
|
6
|
+
Project-URL: Homepage, https://vac-security.com
|
|
7
|
+
Project-URL: Repository, https://github.com/Anne07-Ai/visual-access-contract
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Topic :: Security
|
|
16
|
+
Requires-Python: >=3.11
|
|
7
17
|
Description-Content-Type: text/markdown
|
|
8
18
|
License-File: LICENSE
|
|
9
|
-
Requires-Dist: playwright
|
|
10
|
-
Requires-Dist: PyYAML
|
|
19
|
+
Requires-Dist: playwright<2,>=1.62.0
|
|
20
|
+
Requires-Dist: PyYAML<7,>=6.0.3
|
|
21
|
+
Requires-Dist: click<9,>=8.1
|
|
22
|
+
Requires-Dist: httpx<1,>=0.28
|
|
23
|
+
Requires-Dist: beautifulsoup4<5,>=4.13
|
|
24
|
+
Requires-Dist: pydantic<3,>=2.11
|
|
11
25
|
Provides-Extra: integration
|
|
12
|
-
Requires-Dist: fastapi
|
|
13
|
-
Requires-Dist: uvicorn
|
|
26
|
+
Requires-Dist: fastapi<1,>=0.115.12; extra == "integration"
|
|
27
|
+
Requires-Dist: uvicorn<1,>=0.34.2; extra == "integration"
|
|
14
28
|
Dynamic: license-file
|
|
15
29
|
|
|
16
30
|
# Visual Access Contract
|
|
17
31
|
|
|
18
32
|
[](https://github.com/Anne07-Ai/visual-access-contract/actions/workflows/contract-validation.yml)
|
|
19
33
|
[](LICENSE)
|
|
20
|
-
[](pyproject.toml)
|
|
21
35
|
|
|
22
36
|
Visual Access Contract checks a versioned, role-specific masking rule against selected API responses, visible DOM text, and rendered pixels in CI. In our four-case synthetic experiment, OCR caught a canvas disclosure that the selected API and DOM checks missed, while API inspection caught a disclosure that never appeared on screen.
|
|
23
37
|
|
|
@@ -25,7 +39,7 @@ Visual Access Contract checks a versioned, role-specific masking rule against se
|
|
|
25
39
|
|
|
26
40
|
## Install from PyPI
|
|
27
41
|
|
|
28
|
-
After the first PyPI publication, install VAC with Python 3.
|
|
42
|
+
After the first PyPI publication, install VAC with Python 3.11 or newer in a virtual environment. Install Tesseract with your system package manager.
|
|
29
43
|
|
|
30
44
|
```bash
|
|
31
45
|
pip install visual-access-contract
|
|
@@ -37,12 +51,12 @@ Use a schema 1.0 contract for `vac check`. See [Getting started](docs/getting-st
|
|
|
37
51
|
|
|
38
52
|
## Try it in 60 seconds
|
|
39
53
|
|
|
40
|
-
After installing Python 3.
|
|
54
|
+
After installing Python 3.11 or later, run these three lines on Ubuntu from a terminal with access to the repository:
|
|
41
55
|
|
|
42
56
|
```bash
|
|
43
57
|
git clone https://github.com/Anne07-Ai/visual-access-contract.git && cd visual-access-contract
|
|
44
58
|
python -m venv .venv && source .venv/bin/activate && sudo apt-get install -y tesseract-ocr && python -m pip install -e . && python -m playwright install --with-deps chromium
|
|
45
|
-
|
|
59
|
+
vac demo
|
|
46
60
|
```
|
|
47
61
|
|
|
48
62
|
The demo starts and stops its own loopback fixture. It prints the selected check results and writes `vac-demo-report.html`, `vac-demo-report.sarif`, and `vac-demo-report.json` in the current directory. The synthetic demo has an expected API finding for support and an expected OCR finding for the viewer. Open the HTML file locally to view the role and field matrix alongside the redacted OCR match.
|
|
@@ -67,7 +81,7 @@ In Case C, the HTML includes the synthetic chart label as character codes. The b
|
|
|
67
81
|
|
|
68
82
|
## Run the baseline
|
|
69
83
|
|
|
70
|
-
Use Python 3.
|
|
84
|
+
Use Python 3.11 or newer, Tesseract OCR, and Playwright Chromium. On Ubuntu, install Tesseract with `sudo apt-get install tesseract-ocr`.
|
|
71
85
|
|
|
72
86
|
```bash
|
|
73
87
|
python -m venv .venv
|
|
@@ -87,7 +101,7 @@ The JSON report is written to `evidence/experiment_report.json`. The flag return
|
|
|
87
101
|
### Output and exit codes
|
|
88
102
|
|
|
89
103
|
```bash
|
|
90
|
-
|
|
104
|
+
vac check --contract examples/contract.yaml --json-stdout --quiet | jq .
|
|
91
105
|
```
|
|
92
106
|
|
|
93
107
|
JSON is written to `vac-results.json` by default. `--json-stdout` sends the same report to stdout without writing a JSON file. SARIF and optional HTML output still go to files. `--quiet` prints one summary with the exit code to stderr, keeping stdout available for JSON.
|
|
@@ -98,6 +112,43 @@ JSON is written to `vac-results.json` by default. `--json-stdout` sends the same
|
|
|
98
112
|
| `1` | With `--enforce`, at least one selected check found a violation or was inconclusive. |
|
|
99
113
|
| `2` | Contract, session, or run setup error. |
|
|
100
114
|
|
|
115
|
+
## Platform backend
|
|
116
|
+
|
|
117
|
+
See [VAC Platform API](vac_platform/README.md) for the Phase 3A Docker Compose stack, agent authentication, and redacted result format.
|
|
118
|
+
|
|
119
|
+
## Dashboard
|
|
120
|
+
|
|
121
|
+
Start the [platform stack](vac_platform/README.md#run-the-development-stack) with `docker compose -f compose.platform.yaml up --build --wait`, then open `http://127.0.0.1:3000`. Sign in with a bootstrapped platform user and create or select an organisation. Compose serves the production React build from nginx and proxies `/api` to FastAPI on the same origin.
|
|
122
|
+
|
|
123
|
+
For React development while the API is running locally:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
cd dashboard
|
|
127
|
+
npm ci
|
|
128
|
+
npm run dev
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Open Vite at `http://localhost:5173`. Its same-origin proxy targets `http://127.0.0.1:8000` by default. Set `VAC_DASHBOARD_API` for a different backend. Run `npm test` for the dashboard suite and auth/API coverage thresholds. Production and development sessions store the token in tab memory, so reopening or refreshing the tab requires sign-in.
|
|
132
|
+
|
|
133
|
+
The dashboard uses React Router v6 as specified, with fixed in-app navigation and bounded initial paths. npm audit still reports [upstream advisories for v6](https://github.com/advisories/GHSA-x8j4-g9rr-8j87). Reassess the router dependency before public deployment.
|
|
134
|
+
|
|
135
|
+
Keys issued before the dashboard migration show no suffix. New keys show only their last four characters after the one-time secret modal is closed.
|
|
136
|
+
|
|
137
|
+
## CI agent and platform bridge
|
|
138
|
+
|
|
139
|
+
Install from this repository with `python -m pip install .`. From the application repository, run
|
|
140
|
+
`vac init` and `vac validate`. Use
|
|
141
|
+
`vac scan --local-only` to check a running synthetic app. With a registered schema 1.1 policy and platform
|
|
142
|
+
credentials, `vac scan` uploads selected-check outcomes and `vac report` displays the latest scan counts.
|
|
143
|
+
See the [CI agent guide](docs/ci-integration.md#upload-selected-checks-to-the-vac-platform) for contract
|
|
144
|
+
registration, the reusable GitHub workflow, and exit codes.
|
|
145
|
+
|
|
146
|
+
## Landing page and production deployment
|
|
147
|
+
|
|
148
|
+
The [landing page](site/README.md) builds with Node 22 into static files for Cloudflare Pages. The
|
|
149
|
+
[production stack](vac_platform/README.md#production-compose) layers hardened containers and a
|
|
150
|
+
database/Redis health check over the existing platform Compose file.
|
|
151
|
+
|
|
101
152
|
## Adoption guides
|
|
102
153
|
|
|
103
154
|
- [Getting started](docs/getting-started.md)
|
|
@@ -1,23 +1,8 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: visual-access-contract
|
|
3
|
-
Version: 0.2.1
|
|
4
|
-
Summary: CI checks for role-specific visibility of synthetic data
|
|
5
|
-
License-Expression: Apache-2.0
|
|
6
|
-
Requires-Python: >=3.12
|
|
7
|
-
Description-Content-Type: text/markdown
|
|
8
|
-
License-File: LICENSE
|
|
9
|
-
Requires-Dist: playwright==1.62.0
|
|
10
|
-
Requires-Dist: PyYAML==6.0.3
|
|
11
|
-
Provides-Extra: integration
|
|
12
|
-
Requires-Dist: fastapi==0.115.12; extra == "integration"
|
|
13
|
-
Requires-Dist: uvicorn==0.34.2; extra == "integration"
|
|
14
|
-
Dynamic: license-file
|
|
15
|
-
|
|
16
1
|
# Visual Access Contract
|
|
17
2
|
|
|
18
3
|
[](https://github.com/Anne07-Ai/visual-access-contract/actions/workflows/contract-validation.yml)
|
|
19
4
|
[](LICENSE)
|
|
20
|
-
[](pyproject.toml)
|
|
21
6
|
|
|
22
7
|
Visual Access Contract checks a versioned, role-specific masking rule against selected API responses, visible DOM text, and rendered pixels in CI. In our four-case synthetic experiment, OCR caught a canvas disclosure that the selected API and DOM checks missed, while API inspection caught a disclosure that never appeared on screen.
|
|
23
8
|
|
|
@@ -25,7 +10,7 @@ Visual Access Contract checks a versioned, role-specific masking rule against se
|
|
|
25
10
|
|
|
26
11
|
## Install from PyPI
|
|
27
12
|
|
|
28
|
-
After the first PyPI publication, install VAC with Python 3.
|
|
13
|
+
After the first PyPI publication, install VAC with Python 3.11 or newer in a virtual environment. Install Tesseract with your system package manager.
|
|
29
14
|
|
|
30
15
|
```bash
|
|
31
16
|
pip install visual-access-contract
|
|
@@ -37,12 +22,12 @@ Use a schema 1.0 contract for `vac check`. See [Getting started](docs/getting-st
|
|
|
37
22
|
|
|
38
23
|
## Try it in 60 seconds
|
|
39
24
|
|
|
40
|
-
After installing Python 3.
|
|
25
|
+
After installing Python 3.11 or later, run these three lines on Ubuntu from a terminal with access to the repository:
|
|
41
26
|
|
|
42
27
|
```bash
|
|
43
28
|
git clone https://github.com/Anne07-Ai/visual-access-contract.git && cd visual-access-contract
|
|
44
29
|
python -m venv .venv && source .venv/bin/activate && sudo apt-get install -y tesseract-ocr && python -m pip install -e . && python -m playwright install --with-deps chromium
|
|
45
|
-
|
|
30
|
+
vac demo
|
|
46
31
|
```
|
|
47
32
|
|
|
48
33
|
The demo starts and stops its own loopback fixture. It prints the selected check results and writes `vac-demo-report.html`, `vac-demo-report.sarif`, and `vac-demo-report.json` in the current directory. The synthetic demo has an expected API finding for support and an expected OCR finding for the viewer. Open the HTML file locally to view the role and field matrix alongside the redacted OCR match.
|
|
@@ -67,7 +52,7 @@ In Case C, the HTML includes the synthetic chart label as character codes. The b
|
|
|
67
52
|
|
|
68
53
|
## Run the baseline
|
|
69
54
|
|
|
70
|
-
Use Python 3.
|
|
55
|
+
Use Python 3.11 or newer, Tesseract OCR, and Playwright Chromium. On Ubuntu, install Tesseract with `sudo apt-get install tesseract-ocr`.
|
|
71
56
|
|
|
72
57
|
```bash
|
|
73
58
|
python -m venv .venv
|
|
@@ -87,7 +72,7 @@ The JSON report is written to `evidence/experiment_report.json`. The flag return
|
|
|
87
72
|
### Output and exit codes
|
|
88
73
|
|
|
89
74
|
```bash
|
|
90
|
-
|
|
75
|
+
vac check --contract examples/contract.yaml --json-stdout --quiet | jq .
|
|
91
76
|
```
|
|
92
77
|
|
|
93
78
|
JSON is written to `vac-results.json` by default. `--json-stdout` sends the same report to stdout without writing a JSON file. SARIF and optional HTML output still go to files. `--quiet` prints one summary with the exit code to stderr, keeping stdout available for JSON.
|
|
@@ -98,6 +83,43 @@ JSON is written to `vac-results.json` by default. `--json-stdout` sends the same
|
|
|
98
83
|
| `1` | With `--enforce`, at least one selected check found a violation or was inconclusive. |
|
|
99
84
|
| `2` | Contract, session, or run setup error. |
|
|
100
85
|
|
|
86
|
+
## Platform backend
|
|
87
|
+
|
|
88
|
+
See [VAC Platform API](vac_platform/README.md) for the Phase 3A Docker Compose stack, agent authentication, and redacted result format.
|
|
89
|
+
|
|
90
|
+
## Dashboard
|
|
91
|
+
|
|
92
|
+
Start the [platform stack](vac_platform/README.md#run-the-development-stack) with `docker compose -f compose.platform.yaml up --build --wait`, then open `http://127.0.0.1:3000`. Sign in with a bootstrapped platform user and create or select an organisation. Compose serves the production React build from nginx and proxies `/api` to FastAPI on the same origin.
|
|
93
|
+
|
|
94
|
+
For React development while the API is running locally:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
cd dashboard
|
|
98
|
+
npm ci
|
|
99
|
+
npm run dev
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Open Vite at `http://localhost:5173`. Its same-origin proxy targets `http://127.0.0.1:8000` by default. Set `VAC_DASHBOARD_API` for a different backend. Run `npm test` for the dashboard suite and auth/API coverage thresholds. Production and development sessions store the token in tab memory, so reopening or refreshing the tab requires sign-in.
|
|
103
|
+
|
|
104
|
+
The dashboard uses React Router v6 as specified, with fixed in-app navigation and bounded initial paths. npm audit still reports [upstream advisories for v6](https://github.com/advisories/GHSA-x8j4-g9rr-8j87). Reassess the router dependency before public deployment.
|
|
105
|
+
|
|
106
|
+
Keys issued before the dashboard migration show no suffix. New keys show only their last four characters after the one-time secret modal is closed.
|
|
107
|
+
|
|
108
|
+
## CI agent and platform bridge
|
|
109
|
+
|
|
110
|
+
Install from this repository with `python -m pip install .`. From the application repository, run
|
|
111
|
+
`vac init` and `vac validate`. Use
|
|
112
|
+
`vac scan --local-only` to check a running synthetic app. With a registered schema 1.1 policy and platform
|
|
113
|
+
credentials, `vac scan` uploads selected-check outcomes and `vac report` displays the latest scan counts.
|
|
114
|
+
See the [CI agent guide](docs/ci-integration.md#upload-selected-checks-to-the-vac-platform) for contract
|
|
115
|
+
registration, the reusable GitHub workflow, and exit codes.
|
|
116
|
+
|
|
117
|
+
## Landing page and production deployment
|
|
118
|
+
|
|
119
|
+
The [landing page](site/README.md) builds with Node 22 into static files for Cloudflare Pages. The
|
|
120
|
+
[production stack](vac_platform/README.md#production-compose) layers hardened containers and a
|
|
121
|
+
database/Redis health check over the existing platform Compose file.
|
|
122
|
+
|
|
101
123
|
## Adoption guides
|
|
102
124
|
|
|
103
125
|
- [Getting started](docs/getting-started.md)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "visual-access-contract"
|
|
7
|
+
version = "0.3.0"
|
|
8
|
+
description = "CI checks for role-specific visibility of synthetic data"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.11"
|
|
13
|
+
dependencies = [
|
|
14
|
+
"playwright>=1.62.0,<2",
|
|
15
|
+
"PyYAML>=6.0.3,<7",
|
|
16
|
+
"click>=8.1,<9",
|
|
17
|
+
"httpx>=0.28,<1",
|
|
18
|
+
"beautifulsoup4>=4.13,<5",
|
|
19
|
+
"pydantic>=2.11,<3",
|
|
20
|
+
]
|
|
21
|
+
classifiers = [
|
|
22
|
+
"Development Status :: 3 - Alpha",
|
|
23
|
+
"Environment :: Console",
|
|
24
|
+
"Intended Audience :: Developers",
|
|
25
|
+
"Programming Language :: Python :: 3",
|
|
26
|
+
"Programming Language :: Python :: 3.11",
|
|
27
|
+
"Programming Language :: Python :: 3.12",
|
|
28
|
+
"Programming Language :: Python :: 3.13",
|
|
29
|
+
"Topic :: Security",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://vac-security.com"
|
|
34
|
+
Repository = "https://github.com/Anne07-Ai/visual-access-contract"
|
|
35
|
+
|
|
36
|
+
[project.optional-dependencies]
|
|
37
|
+
integration = ["fastapi>=0.115.12,<1", "uvicorn>=0.34.2,<1"]
|
|
38
|
+
|
|
39
|
+
[project.scripts]
|
|
40
|
+
vac = "vac_cli.commands:cli"
|
|
41
|
+
|
|
42
|
+
[tool.setuptools]
|
|
43
|
+
include-package-data = false
|
|
44
|
+
|
|
45
|
+
[tool.setuptools.packages.find]
|
|
46
|
+
where = ["."]
|
|
47
|
+
include = ["vac_cli", "vac_cli.*"]
|
|
48
|
+
namespaces = false
|
|
49
|
+
|
|
50
|
+
[tool.setuptools.package-data]
|
|
51
|
+
vac_cli = ["template.yaml", "py.typed"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""VAC CI agent and command group."""
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Command-line entry point for the installed VAC package."""
|
|
2
|
+
|
|
3
|
+
import click
|
|
4
|
+
|
|
5
|
+
from vac_cli.commands import cli
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main(argv: list[str] | None = None) -> int:
|
|
9
|
+
try:
|
|
10
|
+
return cli.main(args=argv, prog_name="vac", standalone_mode=False) or 0
|
|
11
|
+
except click.ClickException as exc:
|
|
12
|
+
exc.show()
|
|
13
|
+
return exc.exit_code
|
|
14
|
+
except click.Abort:
|
|
15
|
+
click.echo("Aborted!", err=True)
|
|
16
|
+
return 1
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
if __name__ == "__main__":
|
|
20
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"""Schema for explicit, synthetic-only CI scan policies."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import re
|
|
5
|
+
from hashlib import sha256
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Annotated, Literal
|
|
8
|
+
from urllib.parse import urlsplit
|
|
9
|
+
from uuid import UUID
|
|
10
|
+
|
|
11
|
+
import yaml
|
|
12
|
+
from pydantic import (
|
|
13
|
+
UUID4,
|
|
14
|
+
BaseModel,
|
|
15
|
+
ConfigDict,
|
|
16
|
+
Field,
|
|
17
|
+
ValidationError,
|
|
18
|
+
field_validator,
|
|
19
|
+
model_validator,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
from vac_cli.contract import ContractError, UniqueLoader, _origin
|
|
23
|
+
|
|
24
|
+
VERSION = "1.1"
|
|
25
|
+
MAX_CHECKS = 300
|
|
26
|
+
MAX_CONTRACT_BYTES = 131072
|
|
27
|
+
Identifier = Annotated[str, Field(pattern=r"^[A-Za-z0-9_.-]{1,64}$")]
|
|
28
|
+
PathString = Annotated[str, Field(pattern=r"^/(?:[A-Za-z0-9_~.-]+/)*[A-Za-z0-9_~.-]*$", max_length=512)]
|
|
29
|
+
Name = r"[A-Za-z_][A-Za-z0-9_-]*"
|
|
30
|
+
Atom = rf"(?:[.#]{Name}|\[(?:data-{Name}|id|class|name|role)=(?:'[-\w ]{{1,64}}'|\"[-\w ]{{1,64}}\")\])"
|
|
31
|
+
SimpleSelector = rf"(?:{Name}(?:{Atom}){{0,4}}|(?:{Atom}){{1,4}})"
|
|
32
|
+
SELECTOR = re.compile(rf"{SimpleSelector}(?:(?: +| *> *){SimpleSelector}){{0,5}}", re.ASCII)
|
|
33
|
+
SCREEN_WIDTH, SCREEN_HEIGHT = 1280, 800
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class Strict(BaseModel):
|
|
37
|
+
model_config = ConfigDict(extra="forbid", strict=True)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class Auth(Strict):
|
|
41
|
+
type: Literal["bearer", "cookie", "header", "none"]
|
|
42
|
+
token_env: Annotated[str, Field(pattern=r"^APP_[A-Z0-9_]{1,60}$")] | None = None
|
|
43
|
+
name: Identifier | None = None
|
|
44
|
+
|
|
45
|
+
@model_validator(mode="after")
|
|
46
|
+
def credentials(self):
|
|
47
|
+
if self.type == "none":
|
|
48
|
+
valid = self.token_env is None and self.name is None
|
|
49
|
+
elif self.type == "bearer":
|
|
50
|
+
valid = self.token_env is not None and self.name is None
|
|
51
|
+
elif self.type == "cookie":
|
|
52
|
+
valid = self.token_env is not None and self.name is not None
|
|
53
|
+
else:
|
|
54
|
+
valid = self.token_env is not None and bool(
|
|
55
|
+
self.name and re.fullmatch(r"X-[A-Za-z0-9-]+", self.name, re.IGNORECASE)
|
|
56
|
+
)
|
|
57
|
+
if not valid:
|
|
58
|
+
raise ValueError("Auth requires an APP_ credential and a valid cookie or X- header name when applicable")
|
|
59
|
+
return self
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class Region(Strict):
|
|
63
|
+
x: Annotated[int, Field(ge=0, lt=SCREEN_WIDTH)]
|
|
64
|
+
y: Annotated[int, Field(ge=0, lt=SCREEN_HEIGHT)]
|
|
65
|
+
w: Annotated[int, Field(gt=0, le=SCREEN_WIDTH)]
|
|
66
|
+
h: Annotated[int, Field(gt=0, le=SCREEN_HEIGHT)]
|
|
67
|
+
|
|
68
|
+
@model_validator(mode="after")
|
|
69
|
+
def fits_viewport(self):
|
|
70
|
+
if self.x + self.w > SCREEN_WIDTH or self.y + self.h > SCREEN_HEIGHT:
|
|
71
|
+
raise ValueError("OCR region exceeds the fixed viewport")
|
|
72
|
+
return self
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class Structured(Strict):
|
|
76
|
+
type: Literal["structured"]
|
|
77
|
+
json_path: Annotated[str, Field(pattern=r"^\$\.[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)*$", max_length=256)]
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class StructuredDOM(Strict):
|
|
81
|
+
type: Literal["structured_dom"]
|
|
82
|
+
selector: Annotated[str, Field(min_length=1, max_length=256)]
|
|
83
|
+
|
|
84
|
+
@field_validator("selector")
|
|
85
|
+
@classmethod
|
|
86
|
+
def supported_selector(cls, value):
|
|
87
|
+
if not SELECTOR.fullmatch(value):
|
|
88
|
+
raise ValueError("Use a simple CSS selector with optional child or descendant combinators")
|
|
89
|
+
return value
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class Visual(Strict):
|
|
93
|
+
type: Literal["visual"]
|
|
94
|
+
region: Region
|
|
95
|
+
text: Annotated[str, Field(pattern=r"^[A-Za-z0-9][A-Za-z0-9 ._-]{2,63}$")]
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
Check = Annotated[Structured | StructuredDOM | Visual, Field(discriminator="type")]
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class Rule(Strict):
|
|
102
|
+
rule_id: Identifier
|
|
103
|
+
field: Identifier
|
|
104
|
+
visibility: Literal["visible", "hidden"]
|
|
105
|
+
checks: Annotated[list[Check], Field(min_length=1, max_length=3)]
|
|
106
|
+
|
|
107
|
+
@model_validator(mode="after")
|
|
108
|
+
def unique_checks(self):
|
|
109
|
+
if len({check.type for check in self.checks}) != len(self.checks):
|
|
110
|
+
raise ValueError("Check types must be unique within a rule")
|
|
111
|
+
return self
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class Role(Strict):
|
|
115
|
+
role: Identifier
|
|
116
|
+
auth: Auth | None = None
|
|
117
|
+
rules: Annotated[list[Rule], Field(min_length=1, max_length=MAX_CHECKS)]
|
|
118
|
+
|
|
119
|
+
@model_validator(mode="after")
|
|
120
|
+
def unique_rules(self):
|
|
121
|
+
if len({rule.rule_id for rule in self.rules}) != len(self.rules):
|
|
122
|
+
raise ValueError("Rule IDs must be unique within a role")
|
|
123
|
+
return self
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
class Scenario(Strict):
|
|
127
|
+
id: Identifier
|
|
128
|
+
endpoint: PathString
|
|
129
|
+
page: PathString | None = None
|
|
130
|
+
identity_path: PathString | None = None
|
|
131
|
+
auth: Auth | None = None
|
|
132
|
+
roles: Annotated[list[Role], Field(min_length=1, max_length=20)]
|
|
133
|
+
|
|
134
|
+
@model_validator(mode="after")
|
|
135
|
+
def validate_roles(self):
|
|
136
|
+
if len({role.role for role in self.roles}) != len(self.roles):
|
|
137
|
+
raise ValueError("Role names must be unique within a scenario")
|
|
138
|
+
if any(segment in {".", ".."} for path in (self.endpoint, self.page, self.identity_path)
|
|
139
|
+
if path for segment in path.split("/")):
|
|
140
|
+
raise ValueError("Paths cannot contain traversal segments")
|
|
141
|
+
auths = [role.auth or self.auth for role in self.roles]
|
|
142
|
+
if any(auth is None for auth in auths):
|
|
143
|
+
raise ValueError("Declare auth for every role or at scenario level")
|
|
144
|
+
tokens = [auth.token_env for auth in auths]
|
|
145
|
+
if len(set(tokens)) != len(tokens):
|
|
146
|
+
raise ValueError("Use distinct credentials for different roles in a scenario")
|
|
147
|
+
return self
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
class CIContract(Strict):
|
|
151
|
+
schema_version: Literal["1.1"]
|
|
152
|
+
synthetic_only: Literal[True]
|
|
153
|
+
origin: Annotated[str, Field(min_length=1, max_length=300)]
|
|
154
|
+
scenarios: Annotated[list[Scenario], Field(min_length=1, max_length=20)]
|
|
155
|
+
|
|
156
|
+
@field_validator("synthetic_only", mode="before")
|
|
157
|
+
@classmethod
|
|
158
|
+
def require_synthetic(cls, value):
|
|
159
|
+
if value is not True:
|
|
160
|
+
raise ValueError("synthetic_only must be true")
|
|
161
|
+
return value
|
|
162
|
+
|
|
163
|
+
@field_validator("origin")
|
|
164
|
+
@classmethod
|
|
165
|
+
def canonical_origin(cls, value):
|
|
166
|
+
parts = urlsplit(value)
|
|
167
|
+
if any(ord(char) < 33 or ord(char) > 126 for char in value) or not re.fullmatch(
|
|
168
|
+
r"[A-Za-z0-9.\-:\[\]]+", parts.netloc
|
|
169
|
+
):
|
|
170
|
+
raise ValueError("Invalid origin host")
|
|
171
|
+
return _origin(value)
|
|
172
|
+
|
|
173
|
+
@model_validator(mode="after")
|
|
174
|
+
def selected_check_limit(self):
|
|
175
|
+
if len({scenario.id for scenario in self.scenarios}) != len(self.scenarios):
|
|
176
|
+
raise ValueError("Scenario IDs must be unique")
|
|
177
|
+
if len(self.selected_checks()) > MAX_CHECKS:
|
|
178
|
+
raise ValueError("Contract exceeds the 300 selected-check limit")
|
|
179
|
+
return self
|
|
180
|
+
|
|
181
|
+
def selected_checks(self) -> dict[tuple[str, str, str, str], str]:
|
|
182
|
+
return {(scenario.id, rule.rule_id, role.role, check.type): rule.field
|
|
183
|
+
for scenario in self.scenarios for role in scenario.roles
|
|
184
|
+
for rule in role.rules for check in rule.checks}
|
|
185
|
+
|
|
186
|
+
def digest(self) -> str:
|
|
187
|
+
document = self.model_dump(mode="json", exclude_none=True)
|
|
188
|
+
return sha256(json.dumps(document, sort_keys=True, separators=(",", ":")).encode()).hexdigest()
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
class LocalContract(CIContract):
|
|
192
|
+
"""The installation binding stays local and is excluded from the policy fingerprint."""
|
|
193
|
+
|
|
194
|
+
contract_id: UUID4 | None = None
|
|
195
|
+
contract_version: Annotated[int, Field(ge=1)] | None = None
|
|
196
|
+
|
|
197
|
+
@field_validator("contract_id", mode="before")
|
|
198
|
+
@classmethod
|
|
199
|
+
def parse_id(cls, value):
|
|
200
|
+
return UUID(value) if isinstance(value, str) else value
|
|
201
|
+
|
|
202
|
+
@model_validator(mode="after")
|
|
203
|
+
def binding_pair(self):
|
|
204
|
+
if (self.contract_id is None) != (self.contract_version is None):
|
|
205
|
+
raise ValueError("Set both contract_id and contract_version")
|
|
206
|
+
return self
|
|
207
|
+
|
|
208
|
+
def document(self) -> CIContract:
|
|
209
|
+
return CIContract.model_validate(self.model_dump(exclude={"contract_id", "contract_version"}))
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
class BoundedLoader(UniqueLoader):
|
|
213
|
+
def compose_node(self, parent, index):
|
|
214
|
+
if self.check_event(yaml.AliasEvent) or self.peek_event().anchor is not None:
|
|
215
|
+
raise ContractError("YAML anchors and aliases are unsupported")
|
|
216
|
+
return super().compose_node(parent, index)
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def read_policy(path: Path) -> object:
|
|
220
|
+
try:
|
|
221
|
+
with path.open("rb") as file:
|
|
222
|
+
data = file.read(MAX_CONTRACT_BYTES + 1)
|
|
223
|
+
if len(data) > MAX_CONTRACT_BYTES:
|
|
224
|
+
raise ContractError("Contract exceeds 128 KiB")
|
|
225
|
+
return yaml.load(data.decode("utf-8"), Loader=BoundedLoader)
|
|
226
|
+
except (OSError, UnicodeError, yaml.YAMLError, RecursionError):
|
|
227
|
+
raise ContractError("Could not read or parse the contract") from None
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def parse_policy(raw: object) -> LocalContract:
|
|
231
|
+
try:
|
|
232
|
+
return LocalContract.model_validate(raw)
|
|
233
|
+
except ValidationError as exc:
|
|
234
|
+
# Locations use known schema names only, so a submitted key or value cannot leak.
|
|
235
|
+
known = {
|
|
236
|
+
"schema_version", "synthetic_only", "origin", "scenarios", "id", "endpoint", "page",
|
|
237
|
+
"identity_path", "roles", "role", "auth", "type", "token_env", "name", "rules", "rule_id",
|
|
238
|
+
"field", "visibility", "checks", "structured", "structured_dom", "visual", "json_path",
|
|
239
|
+
"selector", "region", "x", "y", "w", "h", "text", "contract_id", "contract_version",
|
|
240
|
+
}
|
|
241
|
+
errors = exc.errors(include_input=False, include_context=False, include_url=False)
|
|
242
|
+
locations = sorted({".".join(str(part) for part in error["loc"]
|
|
243
|
+
if isinstance(part, int) or part in known) or "contract"
|
|
244
|
+
for error in errors})
|
|
245
|
+
raise ContractError(f"Invalid schema 1.1 policy at {', '.join(locations[:8])}") from None
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def load_policy(path: Path) -> LocalContract:
|
|
249
|
+
return parse_policy(read_policy(path))
|
|
@@ -9,10 +9,10 @@ import time
|
|
|
9
9
|
|
|
10
10
|
from playwright.async_api import Error
|
|
11
11
|
|
|
12
|
-
from
|
|
13
|
-
from
|
|
14
|
-
from
|
|
15
|
-
from
|
|
12
|
+
from vac_cli.contract import ContractError, load_contract
|
|
13
|
+
from vac_cli.html_report import write_html_report
|
|
14
|
+
from vac_cli.output import write_reports
|
|
15
|
+
from vac_cli.runner import run
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
def _watch(args: argparse.Namespace) -> int:
|