diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ed89750 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,74 @@ +name: Release + +# Runs only when someone publishes a GitHub release. PyPI trusts this workflow +# (trusted publishing), so there is no token to store. +on: + release: + types: [published] + +permissions: + contents: read + +concurrency: + group: release-${{ github.event.release.tag_name }} + cancel-in-progress: false + +env: + UV_VERSION: "0.13.10" + +jobs: + build: + name: Check and build + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + persist-credentials: false + - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0 + with: + version: ${{ env.UV_VERSION }} + python-version: "3.13" + enable-cache: false + - name: Check that the release is on main and carries its version + shell: bash + env: + TAG: ${{ github.event.release.tag_name }} + run: | + git merge-base --is-ancestor "$GITHUB_SHA" origin/main || + { echo "::error::the tagged commit is not on main"; exit 1; } + version=$(uv version --short) + [ "$TAG" = "v$version" ] || + { echo "::error::tag $TAG does not match version $version"; exit 1; } + grep -qE "^## ${version//./[.]}( |$)" CHANGELOG.md || + { echo "::error::CHANGELOG.md has no section for $version"; exit 1; } + - run: uv sync --locked + - run: uv run --no-sync ruff check . + - run: uv run --no-sync mypy + - run: uv run --no-sync pytest + - run: uv build + - run: uv run --no-sync twine check --strict dist/* + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: dist + path: dist/ + if-no-files-found: error + + publish: + name: Publish to PyPI + needs: build + runs-on: ubuntu-latest + timeout-minutes: 10 + environment: + name: pypi + url: https://pypi.org/p/vulnradar + permissions: + id-token: write # proves to PyPI which workflow is publishing + steps: + # Nothing from the repository runs in this job, which can publish. + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: dist + path: dist/ + - uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3 diff --git a/CHANGELOG.md b/CHANGELOG.md index 75cbba3..f07a9d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,118 +7,62 @@ dates on PyPI (UTC). ## Unreleased -### Added +## 3.0.0b1 -- The package ships `py.typed`, so type checkers use its annotations. -- `VULNRADAR_TOKEN` and `VULNRADAR_API_BASE` are used when `api_key` or - `base_url` is not given. -- `NetworkError`, `RequestTimeoutError`, `UnexpectedResponseError` and - `RateLimitKind`. `RateLimitInfo` is exported. -- Errors carry `code`, `request_id`, `retry_after` and `body`, and a - `RateLimitError` says which limit was reached in `kind`. -- `client.scans` starts scans and crawls, reports their progress, waits for them - and cancels them, with `ScanJob`, `ScanStatus`, `ScanState` and `ScanOptions`. -- `ScanFailedError` and `ScanTimeoutError`. An error raised while waiting names - the scan in `scan_id`. -- Scan options: `public`, `capture_screenshot`, `port_scan` and `team_ids`. -- `Scanner` lists the scanner names. -- Results keep the server's whole reply in `raw`, and have `public_id`, - `incomplete` and `tags`. Findings have their category, evidence, fix steps, - `suppressed` and `remediation_status` among other details. -- History can be searched, paged and iterated, and scans changed, deleted all at - once or downloaded as reports: `history.iterate()`, `update()`, - `delete_all()` and `report()`, with `ScanSettings`, `Report` and - `ReportFormat`. -- `client.me()` returns the `Account` behind the key, and - `metadata.plan_limits()` the published plan limits. -- Bulk and signed-in scans (`scans.bulk()`, `scans.authenticated()`), AI review - (`scans.verify()`, `verify_batch()`, `history.summary()`), subdomain search - (`discovery.subdomains()`, `subdomain_progress()`), `reputation()`, - `demo_scan()` and `verify_webhook()`. -- `incomplete` holds `authenticated-session` when a login was lost. -- `NoResultError` for a stored scan that is still running or failed, raised by - `history.get()` and `history.report()`. A `Report` says what the scan did not - check in `incomplete`. +A rebuild for version 3 of the API. No earlier release works with the current service. +It has been tested against the server's source code, not yet against a live server. -### Changed +### Upgrading from 2.0.0b2 -- The client calls the v3 API. `scan()` and `scan_crawl()` wait for the - background scan to finish, for 960 seconds unless `timeout` says otherwise. -- Scanner names are checked before a scan is sent. -- `ScanResult.duration` is now `duration_ms`, in milliseconds, and - `scanned_at` is `None` when the server gives no time. -- `CrawlResult` is a `ScanResult` with `pages`, `pages_discovered`, - `pages_scanned`, `pages_skipped` and `pages_unreachable`. -- `CrawlPage.duration` is now `duration_ms`, and `ScanResult`, `Finding` and - `CrawlPage` take different constructor arguments. -- `incomplete` also holds `page-checks` when checks failed to run, and - `crawl-pages-not-scanned` when a crawl left pages out, for servers that do not - say so themselves. -- Summary counts that are not numbers are an error. -- `history.list()` takes keyword arguments and returns `total`, `matched`, - `limit`, `offset` and `truncated` beside the scans. -- `HistoryScan.id` is the text id, `duration` is `duration_ms`, `tags` are - names, `scanned_at` may be `None`, and `summary` and `findings_count` are - `None` without a result. `notes` is gone: the list does not send it. -- `history.get()` returns a `CrawlResult` for a crawl. -- `FindingTypesResult` has `categories` instead of `version`, and - `FindingType` has `description`, cannot be changed and compares all its fields. -- `VersionInfo.latest` and `engine` may be `None`, `status` is `unknown` when - missing, and it also has `release_url`, `api` and `raw`. -- `HistoryList` and `FindingTypesResult` have no default values, and a delete - reply must say `true` or `false`. -- An unfamiliar severity is `Severity.UNKNOWN`, not `info`. -- Targets without a scheme, with punycode or underscore host names, or using any - scheme the server knows are no longer rejected. -- `retries` counts the attempts after the first, with a default of 2, and only - reads are retried. -- `discover_urls()` adds `https://` to an address without a scheme. -- A web page in reply raises `UnexpectedResponseError`, not - `AuthenticationError`. -- A reply without the fields a result needs raises `UnexpectedResponseError` - instead of giving an empty result. -- Rate limit figures the server did not send are `None`, not zero. -- A missing or unusable key, address or number raises `ValueError` when the - client is created. `base_url` must include the API path. -- `history.get()` and `history.delete()` raise `ValueError` for an id holding - anything but letters, digits, `_` and `-`. -- `timeout` may be a fraction of a second. - Python 3.11 or newer is required. -- `requests` 2.33.0 or newer is required, which leaves out PYSEC-2026-2275. -- `Severity` is a `StrEnum`: `str()` and f-strings now give the value, such as - `high`. -- `__version__` is read from the installed package, and is `unknown` when the - source is used without being installed. -- The README now says that no published release works with the current API. - -### Removed - -- `Finding.type`, which the server never sends, and `Finding.remediation`; use - `fix_steps` and `remediation_status`. -- `CrawlInfo`, `CrawlResult.crawl` and `CrawlPage.response_headers`. -- `vulnradar.utils.parse_rate_limit_headers`, and the `VERSION_URL` and - `RATE_LIMIT_*_HEADER` constants. - -### Fixed - -- `vulnradar.__version__` reports the same version as the package metadata. -- Network failures, unreadable replies and odd rate limit headers raise SDK - errors instead of other exceptions. -- The version address keeps the path prefix of a self-hosted `base_url`. -- `history.get()` sets `scan_history_id`, and a cut-short crawl read from - history is marked incomplete. -- `history.list()` reads the server's replies, and finding types are no longer - equal just because one field matches. +- `scan()` and `scan_crawl()` wait for the background scan to finish, for 960 seconds + unless `timeout` says otherwise, and take options such as `public` and `team_ids`. +- `ScanResult.duration` is `duration_ms` in milliseconds, and `scanned_at` may be `None`. +- `Finding.type` and `Finding.remediation` are gone: use `fix_steps` and + `remediation_status`. An unfamiliar severity is `Severity.UNKNOWN`, not `info`. +- `CrawlResult` is a `ScanResult` with `pages`, `pages_discovered`, `pages_scanned`, + `pages_skipped` and `pages_unreachable`. `CrawlInfo`, `CrawlResult.crawl` and + `CrawlPage.response_headers` are gone; `CrawlPage.duration` is `duration_ms`. +- `history.list()` takes keyword arguments and returns `total`, `matched`, `limit`, + `offset` and `truncated`. `HistoryScan.id` is the text id, `tags` are names, + `summary` and `findings_count` are `None` without a result, and `notes` is gone. +- `history.get()` returns a `CrawlResult` for a crawl. +- `FindingTypesResult` has `categories` instead of `version`. `FindingType` cannot be + changed and compares all its fields. +- `VersionInfo.latest` and `engine` may be `None`. +- `retries` counts the attempts after the first (default 2), and only reads are retried. +- Failures raise errors where an empty or partial result came back before: unreadable + replies, a web page (`UnexpectedResponseError`), a missing key or bad setting + (`ValueError`), and a scan id with characters an address could be changed by. +- `base_url` must include the API path. `Severity` is a `StrEnum`. +- Result classes take different constructor arguments, and rate limit figures the + server did not send are `None`. +- `vulnradar.utils.parse_rate_limit_headers` and the `VERSION_URL` and + `RATE_LIMIT_*_HEADER` constants are gone. + +### Added + +- `client.scans` to start, follow, wait for and cancel scans and crawls, to queue many + (`bulk()`), to scan while signed in (`authenticated()`) and to have findings + reviewed by the server's AI. +- History search, paging and `iterate()`, `update()`, `delete_all()`, `report()` and + `summary()`. +- `client.me()`, `reputation()`, `demo_scan()`, `discovery.subdomains()`, + `metadata.plan_limits()` and `verify_webhook()`. +- `incomplete` on results names what was not checked, including cases older servers + do not report themselves. +- Errors for network failures, unreadable replies, failed and unfinished scans, with + the server's code, request id, `Retry-After` and which rate limit was reached. +- `VULNRADAR_TOKEN` and `VULNRADAR_API_BASE`, `py.typed`, and the whole server reply + in `raw`. ### Security -- A request that starts or deletes something is never sent twice. -- `base_url` must use `https`, except for this computer, and a plain `http` - request never goes through a proxy. -- Redirects are not followed. -- The key is not shown when the client's settings are printed, and a `.netrc` - entry cannot replace it. -- A scan id cannot change the address of a request. +- A request that starts, changes or deletes something is sent once. +- The key goes only to the configured address: `https` except for this computer, no + redirects, no proxy for plain `http`, and no `.netrc` override. It does not appear in + printed settings or network errors. +- `requests` 2.33.0 or newer, which leaves out PYSEC-2026-2275. ## 2.0.0b2 - 2026-03-16 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..2c2bffc --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,81 @@ +# Contributing + +## Setup and checks + +Development uses [uv](https://docs.astral.sh/uv/) and Python 3.11 or newer. Create a +branch, and before opening a pull request run: + +```bash +uv sync +uv run ruff check . +uv run ruff format --check . +uv run mypy +uv run pytest +``` + +Commits follow [Conventional Commits](https://www.conventionalcommits.org/). Add a line +to `CHANGELOG.md` for anything a user would notice. + +## How the code is laid out + +| Path | What it holds | +|---|---| +| `vulnradar/client.py` | The `VulnRadar` class, the entry point | +| `vulnradar/services/` | One class per group of API calls | +| `vulnradar/models/` | Replies turned into objects | +| `vulnradar/http.py` | The only code that sends requests: key, retries, errors | +| `vulnradar/replies.py` | Turns an unreadable reply into an error | +| `vulnradar/webhooks.py` | Webhook signature check | +| `tests/` | Offline tests; `tests/samples.py` holds server replies | + +Two rules matter more than the rest: + +- A scan that is unfinished, failed or only partly checked must never look clean. Raise, + or name what is missing in `incomplete`. +- A request that starts, changes or deletes something is sent once, and the key goes only + to the configured address. + +The server's source is [VulnRadar/vulnradar.dev](https://github.com/VulnRadar/vulnradar.dev). +Write test replies from its routes, not from what the SDK expects. + +## Live tests + +`tests/live` calls a real server, spends scan quota and deletes the scans it creates. +Run it only on purpose, against a site you may scan, with a key in `VULNRADAR_TOKEN`: + +```bash +uv run pytest -m live +``` + +`VULNRADAR_API_BASE` points it at another server and `VULNRADAR_TEST_URL` changes the +target. Crawls need several scans of quota. + +## Releasing + +Once, before the first release: + +- In the repository settings, give the `pypi` environment a required reviewer and allow + deployments from tags matching `v*` only, and add a tag ruleset so that only + maintainers can create such tags. This is required: the checks in the workflow come from + the tagged commit, so only these settings stop someone with write access from releasing + other code. +- On PyPI, an owner of the `vulnradar` project adds a trusted publisher: GitHub owner + `VulnRadar`, repository `Python-SDK`, workflow `release.yml`, environment `pypi`. + +For each release: + +1. In one pull request, set `version` in `pyproject.toml`, run `uv lock`, and give the + version its section in `CHANGELOG.md`. +2. Run the live tests. +3. After merging, publish a GitHub release from `main`. The tag is `v` plus the version, + the title is the same, and the body is that changelog section. Mark betas as + pre-releases. + +```bash +gh release create v3.0.0b1 --target main --title v3.0.0b1 --notes-file notes.md --prerelease +``` + +Publishing the release builds, checks and uploads the package. + +To roll back, yank the version on PyPI (the files stay, but `pip` stops choosing it) and +release a fixed one. A version number cannot be used twice. diff --git a/README.md b/README.md index 91c57e0..16c6cff 100644 --- a/README.md +++ b/README.md @@ -1,40 +1,45 @@ # VulnRadar Python SDK -A Python SDK for the [VulnRadar](https://vulnradar.dev) security scanning API. - -> **This SDK is being rebuilt and does not work yet.** Every release published so far -> (0.1.0, 2.0.0b1 and 2.0.0b2) calls the retired v1 or v2 API. Against vulnradar.dev -> today, only `client.version()` succeeds in them. Version 0.1.0, which -> `pip install vulnradar` currently installs, also prints each successful API response to -> the console, so avoid it. Until a new release is out, call the -> [v3 API](https://vulnradar.dev/docs/api) directly. -> -> The code on `main` calls the v3 API, and this page describes it. It has not been -> released yet. +The Python library for the [VulnRadar](https://vulnradar.dev) security scanning API: scan addresses and +crawl sites, read your scan history, download reports and check webhooks, with typed +results and errors. It uses version 3 of the API (`/api/v3`). ---- +> **Version 3 is a beta.** Releases before it (0.1.0, 2.0.0b1 and 2.0.0b2) call API +> versions that no longer exist and do not work. Version 0.1.0 also prints API responses +> to the console. + +## Only scan what you may -## Overview +Scan only sites you own or have written permission to test. Using this library means +using VulnRadar, under its [Terms of Service](https://vulnradar.dev/legal/terms), +[Acceptable Use Policy](https://vulnradar.dev/legal/acceptable-use) and +[Privacy Policy](https://vulnradar.dev/legal/privacy). -VulnRadar scans web targets for security vulnerabilities, exposing findings categorized by severity (critical, high, medium, low, info). This SDK wraps the REST API with: +## What this library sends -- Full type hints and dataclass-based response models -- Automatic authentication header injection -- Structured error handling with custom exceptions -- Rate limit awareness via response header parsing -- Configurable timeout and retry logic -- Support for single scans, deep crawl scans, URL discovery, and history retrieval +It talks only to the server of the API address you configure, +`https://vulnradar.dev/api/v3` unless you change it (`client.version()` reads +`/api/version` on the same server). It sends your API key, what you pass to a call (such as the target and any +login details), and two headers naming the library: a `User-Agent` with the library and +Python versions, and `x-vulnradar-client` with the library version, which servers from +4.0 record against the key. It has no analytics or other telemetry. --- ## Installation +Python 3.11 or newer. + ```bash -pip install vulnradar +pip install "vulnradar>=3.0.0b1" ``` -The releases on PyPI require Python 3.10 or newer. The code on `main` requires Python 3.11 or -newer. +Name the version while 3.0 is a beta: a plain `pip install vulnradar` still picks an old +release. If PyPI has no 3.0 release yet, install from the repository: + +```bash +pip install git+https://github.com/VulnRadar/Python-SDK +``` --- @@ -529,32 +534,14 @@ if discovery.total > 0: --- -## Contributing - -Development uses [uv](https://docs.astral.sh/uv/). Fork the repository, create a branch, and -before opening a pull request run: - -```bash -uv sync -uv run ruff check . -uv run ruff format --check . -uv run mypy -uv run pytest -``` - -These tests never touch the network. The tests in `tests/live` call a real server, spend scan -quota and delete the scans they create. Run them only on purpose, with a key in -`VULNRADAR_TOKEN`: - -```bash -uv run pytest -m live -``` +## Contributing and security -`VULNRADAR_API_BASE` points them at another server and `VULNRADAR_TEST_URL` changes the scan -target. +See [CONTRIBUTING.md](https://github.com/VulnRadar/Python-SDK/blob/main/CONTRIBUTING.md). Report security problems as described in +[SECURITY.md](https://github.com/VulnRadar/Python-SDK/blob/main/SECURITY.md), not in a public issue. Changes are listed in the +[changelog](https://github.com/VulnRadar/Python-SDK/blob/main/CHANGELOG.md). --- ## License -MIT. See [LICENSE](LICENSE) for details. +MIT. See [LICENSE](https://github.com/VulnRadar/Python-SDK/blob/main/LICENSE) for details. diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..2301c9a --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,20 @@ +# Security + +## Reporting a vulnerability + +Email **security@vulnradar.dev**. Please do not open a public issue for a security +problem. Include the version, what happens and how to reproduce it, and leave real +API keys, passwords and personal data out of the report. + +Problems in the VulnRadar service itself are covered by the +[platform's security policy](https://github.com/VulnRadar/vulnradar.dev/blob/main/SECURITY.md). + +## Supported versions + +Fixes go into the newest release. Releases before 3.0.0 call API versions that no +longer exist and are not fixed. + +## If your API key may have leaked + +Revoke it under Settings, API Keys, and create a new one. Version 0.1.0 of this +package printed API responses to the console, so check old logs if you used it. diff --git a/pyproject.toml b/pyproject.toml index 461a7fc..77ab9d3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "vulnradar" -version = "2.0.0b2" +version = "3.0.0b1" description = "Python SDK for the VulnRadar security scanning API" readme = "README.md" requires-python = ">=3.11" diff --git a/uv.lock b/uv.lock index 18255a1..d2904c1 100644 --- a/uv.lock +++ b/uv.lock @@ -1457,7 +1457,7 @@ wheels = [ [[package]] name = "vulnradar" -version = "2.0.0b2" +version = "3.0.0b1" source = { editable = "." } dependencies = [ { name = "requests" }, diff --git a/vulnradar/services/history_service.py b/vulnradar/services/history_service.py index f00a38c..59cf3d2 100644 --- a/vulnradar/services/history_service.py +++ b/vulnradar/services/history_service.py @@ -55,8 +55,8 @@ def iterate(self, *, query: str | None = None, tag: str | None = None) -> Iterat """Every matching scan, newest first, fetching pages as they are needed. Each page uses one request of the key's quota. The server orders scans by - when they finished, so one that finishes, or is deleted, while you iterate - can move to another page and be missed. + when they finished, so a scan can be missed if one finishes or is deleted + while you iterate. Raises: UnexpectedResponseError: If the server keeps sending the same page.