Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.git
.github
tests
__pycache__
*.pyc
.DS_Store
*.db
*.zip
*.json.tmp
108 changes: 108 additions & 0 deletions .github/workflows/pathscope.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Example CI pipeline for PathScope.
#
# It does three things, in order:
# 1. runs the unit test suite (no network, no dependencies),
# 2. runs the built-in self-test,
# 3. if a capture was attached to the run (artifact "pathscope-input"),
# analyses it with a policy gate and publishes JUnit + an HTML report.
#
# PathScope is passive: this workflow never contacts the targets in the
# capture. Replace the artifact step with wherever your capture comes from
# (proxy export, browser HAR, Postman collection, ...).
name: pathscope

on:
push:
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
test:
name: Unit tests and self-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Run the unit tests
run: python3 -m unittest discover -s tests -v
- name: Run the built-in self-test
run: python3 path_detector.py --no-banner --self-test
- name: Check the environment
run: python3 path_detector.py --no-banner --doctor

install:
name: Installer smoke test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- name: Install into a throwaway prefix
run: |
./install.sh --dry-run --no-path
PREFIX="$RUNNER_TEMP/pathscope" ./install.sh --no-path
- name: Run the installed launcher
run: |
"$RUNNER_TEMP/pathscope/bin/pathscope" --version
"$RUNNER_TEMP/pathscope/bin/pathscope" --no-banner --self-test
echo 'https://a.test/?file=../../etc/passwd' \
| "$RUNNER_TEMP/pathscope/bin/pathscope" --no-banner -q --format json \
| grep -q '"candidates": 1'
- name: Uninstall
run: PREFIX="$RUNNER_TEMP/pathscope" ./install.sh --uninstall

triage:
name: Triage a capture (optional)
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Download the capture artifact
id: capture
uses: actions/download-artifact@v4
continue-on-error: true
with:
name: pathscope-input
path: input
- name: Analyse with a policy gate
if: steps.capture.outcome == 'success'
id: triage
# Reports are produced first, then the gate decides the job's outcome.
run: |
set +e
python3 path_detector.py \
-i input/capture.har \
--preset balanced \
--policy .pathscope/policy.json \
--output-format junit > pathscope-junit.xml
echo "gate=$?" >> "$GITHUB_OUTPUT"
python3 path_detector.py \
-i input/capture.har \
--preset balanced \
--policy .pathscope/policy.json \
--save-report pathscope-report.html --interactive \
--github-annotations
echo "annotations=$?" >> "$GITHUB_OUTPUT"
- name: Upload reports
if: steps.capture.outcome == 'success'
uses: actions/upload-artifact@v4
with:
name: pathscope-reports
path: |
pathscope-junit.xml
pathscope-report.html
- name: Enforce the policy gate
if: steps.capture.outcome == 'success' && steps.triage.outputs.gate != '0'
run: |
echo "PathScope policy gate failed (exit ${{ steps.triage.outputs.gate }})." >&2
exit 1
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__pycache__/
*.pyc
.venv/
venv/
10 changes: 10 additions & 0 deletions .pathscope/policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"description": "Example gate: no new high-confidence candidates, at most 10 medium, 25 total",
"max_high": 0,
"max_medium": 10,
"max_total": 25,
"min_score": 0,
"fail_on_known": false,
"ignore_rules": [],
"ignore_hosts": []
}
7 changes: 7 additions & 0 deletions .pre-commit-config.example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copy to .pre-commit-config.yaml in your project and run `pre-commit install`.
repos:
- repo: https://github.com/mrdineshpathro/pathscope
rev: v2.2.0
hooks:
- id: pathscope-selftest
- id: pathscope-no-new-high
28 changes: 28 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Pre-commit hook definitions (https://pre-commit.com).
#
# repos:
# - repo: https://github.com/mrdineshpathro/pathscope
# rev: v2.2.0
# hooks:
# - id: pathscope-selftest
# - id: pathscope-no-new-high
#
# Both hooks are offline and read only the files listed by pre-commit.
- id: pathscope-selftest
name: PathScope self-test
description: Verify the PathScope installation (parsing, scoring, escaping).
entry: python3 path_detector.py --no-banner --self-test
language: python
pass_filenames: false
always_run: true

- id: pathscope-no-new-high
name: PathScope (no new high-confidence candidates)
description: >
Analyse the given captures and fail when a new high-confidence candidate
appears. Uses a reviewed ledger when one is provided, so a stable file does
not fail repeatedly.
entry: python3 path_detector.py --no-banner -q --policy '{"max_high": 0}' --top 5
language: python
files: \.(har|json|txt|xml|jsonl)$
types: [file]
45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# PathScope container image.
#
# docker build -t pathscope .
# cat requests.txt | docker run --rm -i pathscope --stream --format text
# docker run --rm -v "$PWD:/data:ro" pathscope -i /data/requests.txt --format json
#
# The image contains nothing but PathScope and a Python runtime: no scanners,
# no networking tools, no third-party packages.

FROM python:3.12-slim AS base

LABEL org.opencontainers.image.title="PathScope" \
org.opencontainers.image.description="Passive, offline triage of path-like request parameters" \
org.opencontainers.image.source="https://github.com/mrdineshpathro/pathscope" \
org.opencontainers.image.licenses="MIT"

ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=0

# Unprivileged user: nothing in PathScope needs root.
RUN groupadd --system --gid 10001 pathscope \
&& useradd --system --uid 10001 --gid pathscope --create-home pathscope

WORKDIR /opt/pathscope
COPY path_detector.py ./
COPY pathscope ./pathscope
COPY assets ./assets
COPY README.md LICENSE ./

# Byte-compile once so runs stay fast; drop the source copies for a smaller layer.
RUN python3 -m compileall -q pathscope path_detector.py \
&& chmod -R a+rX /opt/pathscope

USER pathscope
WORKDIR /home/pathscope

# Inputs are mounted read-only; the default run documents itself.
VOLUME ["/data"]
ENTRYPOINT ["python3", "/opt/pathscope/path_detector.py"]
CMD ["--help"]

# Sanity check used by CI and `docker run --rm pathscope --self-test`.
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=1 \
CMD ["python3", "/opt/pathscope/path_detector.py", "--no-banner", "--self-test"]
Loading
Loading