From bb842737e4c411226e1729dcebb9a0ce6bbe404f Mon Sep 17 00:00:00 2001 From: K <39208150+Kvrnn@users.noreply.github.com> Date: Mon, 9 Nov 2026 06:56:31 -0800 Subject: [PATCH 1/5] chore: publish community policies and public baseline audit --- .github/CODEOWNERS | 2 + .github/ISSUE_TEMPLATE/bug_report.yml | 32 +++++++++ .github/ISSUE_TEMPLATE/config.yml | 5 ++ .github/ISSUE_TEMPLATE/feature_request.yml | 16 +++++ .github/PULL_REQUEST_TEMPLATE.md | 17 +++++ .github/dependabot.yml | 7 ++ .github/workflows/public-repo-drift.yml | 36 ++++++++++ CODE_OF_CONDUCT.md | 11 ++++ CONTRIBUTING.md | 23 +++++++ SECURITY.md | 17 +++++ SUPPORT.md | 7 ++ automation/public_repo_drift.py | 77 ++++++++++++++++++++++ 12 files changed, 250 insertions(+) create mode 100644 .github/CODEOWNERS create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/feature_request.yml create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/public-repo-drift.yml create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 SECURITY.md create mode 100644 SUPPORT.md create mode 100644 automation/public_repo_drift.py diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..68d4e61 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,2 @@ +# Default maintainer; reviews are advisory where a solo-maintainer exception applies. +* @Kvrnn diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..d6d53f5 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,32 @@ +name: Bug report +description: Report a reproducible problem without sensitive data. +body: + - type: markdown + attributes: + value: "For suspected vulnerabilities, follow SECURITY.md instead of opening a public issue. Never include credentials or customer data." + - type: input + id: version + attributes: + label: Version or commit + validations: + required: true + - type: textarea + id: environment + attributes: + label: Environment + description: Relevant OS, runtime and installation method. Exclude private infrastructure details. + validations: + required: true + - type: textarea + id: reproduction + attributes: + label: Minimal reproduction + description: Use synthetic data and list the steps to reproduce. + validations: + required: true + - type: textarea + id: behavior + attributes: + label: Expected and actual behavior + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..88157c3 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,5 @@ +blank_issues_enabled: false +contact_links: + - name: Private security report + url: https://github.com/NightSquawk/.github/blob/v1.0.0/SECURITY.md + about: Follow the private reporting instructions; do not publish vulnerability details here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000..5cdf940 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,16 @@ +name: Feature request +description: Suggest an improvement and describe the need. +body: + - type: textarea + id: problem + attributes: + label: Problem to solve + description: Explain the use case without customer or personal information. + validations: + required: true + - type: textarea + id: proposal + attributes: + label: Proposed behavior and alternatives + validations: + required: true diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..295e8e2 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,17 @@ +## Change + +Describe the problem, resulting behavior and any related issue. + +## Validation + +List checks run and their results. Explain checks that could not run. + +## Compatibility and security + +Describe breaking changes, migration steps, new dependencies, permission changes and security effects. Report undisclosed vulnerabilities privately before opening a public PR. + +- [ ] I have authority to contribute the included work and have checked applicable repository contribution terms. +- [ ] I preserved required licenses and notices and identified new dependencies. +- [ ] I excluded secrets, customer data and private diagnostics. +- [ ] I updated documentation and added meaningful tests where appropriate. +- [ ] I disclosed material AI assistance and reviewed the resulting changes. diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..8004983 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: weekly + open-pull-requests-limit: 5 diff --git a/.github/workflows/public-repo-drift.yml b/.github/workflows/public-repo-drift.yml new file mode 100644 index 0000000..a481438 --- /dev/null +++ b/.github/workflows/public-repo-drift.yml @@ -0,0 +1,36 @@ +name: Public repository baseline audit +on: + schedule: + - cron: '0 15 * * 1' + workflow_dispatch: + pull_request: + paths: + - automation/public_repo_drift.py + - .github/workflows/public-repo-drift.yml +permissions: + contents: read +jobs: + audit: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + with: + persist-credentials: false + - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7 + with: + python-version: '3.12' + - name: Check script syntax + run: python -m py_compile automation/public_repo_drift.py + - name: Audit public baseline + if: github.event_name != 'pull_request' + env: + GH_TOKEN: ${{ github.token }} + run: python automation/public_repo_drift.py --output "$RUNNER_TEMP/public-repo-drift.json" + - name: Upload audit evidence + if: always() && github.event_name != 'pull_request' + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 + with: + name: public-repo-drift + path: ${{ runner.temp }}/public-repo-drift.json + retention-days: 30 diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..45cbd68 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,11 @@ +# Community code of conduct + +Treat contributors and users with respect. Welcome questions, give constructive feedback and discuss technical disagreements without personal attacks. + +Harassment, threats, discriminatory abuse, sexual harassment, impersonation, spam, and publishing someone's private information are not acceptable. Do not pressure others to disclose personal information or continue an unwanted interaction. + +This policy applies to repository issues, pull requests, discussions and other project-managed spaces, and when representing the project publicly. + +Report concerns privately to hello@nightsquawk.tech with links and the information needed to assess the incident. Do not post private evidence publicly. If a report concerns a maintainer, identify that concern so it can be routed away from the subject where possible. A separate independent escalation contact is not currently designated. + +Maintainers consider context, impact and repeated behavior. Responses may include a request to change behavior, content removal, a warning, temporary restrictions or exclusion. Reports are handled with discretion, but absolute confidentiality cannot be guaranteed. Good-faith reports must not lead to retaliation. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..18224a2 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,23 @@ +# Contributing + +Thank you for helping improve the project. Start with its README, existing issues and repository-specific development instructions. For substantial changes, discuss the approach in an issue before implementation. Report vulnerabilities through SECURITY.md rather than a public issue. + +## Issues + +Describe the problem, affected version, environment, expected result and a minimal reproduction. Use synthetic data and remove credentials, personal information and internal infrastructure details. Search for an existing report before opening a duplicate. + +## Pull requests + +1. Create a focused branch from the repository's documented contribution base. Its default branch may be named differently from main. +2. Follow the project's installation and development instructions. Run its applicable build, formatting, lint, type and test checks. State which checks ran and any that could not run. +3. Explain the behavior change, compatibility impact and relevant issue. Add meaningful tests for behavior changes and update user documentation where needed. +4. Preserve license headers, attribution and third-party notices. Discuss new dependencies and their licenses. Keep generated artifacts consistent with the project's existing conventions. +5. Submit a focused PR and respond to review. Do not include unrelated changes, live secrets, customer data or unlicensed copied material. Disclose material AI assistance and verify the resulting code and its provenance yourself. + +## Contribution rights + +The affected repository's license and any applicable contributor agreement govern contributions. Submit only work you are authorized to contribute, including any required employer permission. This shared guide does not grant software usage rights or change an existing license. + +Projects using separate personal and commercial licenses may require an additional contributor agreement before acceptance. Maintainers must publish that agreement and its acceptance process before accepting contributions that depend on additional commercial licensing rights. A PR checklist or sign-off alone does not establish those rights. + +Follow CODE_OF_CONDUCT.md in project interactions. Community review and support are provided as maintainer availability permits. diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..136585b --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,17 @@ +# Security policy + +Please report suspected vulnerabilities privately. Do not include exploit details, credentials, personal information or client data in public issues or pull requests. + +## Reporting + +Use **Security → Advisories → Report a vulnerability** in the affected repository when available. If that route is unavailable, use the [central private reporting form](https://github.com/NightSquawk/.github/security/advisories/new) and identify the affected repository. Do not include live credentials or personal data. + +Include reproduction steps using a test environment, expected and actual behavior, impact, and any proposed fix. Use synthetic examples and redact secrets. Do not access others' data, disrupt services or test systems without authorization. + +## Supported versions + +Follow the affected project's documented support policy. Where no release support table exists, maintainers assess reports against the current default branch and latest release; this does not promise maintenance of older versions. Upstream projects may have separate reporting and support policies. + +## Handling and disclosure + +Maintainers assess scope and impact, coordinate remediation and discuss disclosure timing with the reporter. Security fixes may be developed privately before a public advisory or release. We do not promise a fixed response time, bounty or legal authorization to test third-party systems. diff --git a/SUPPORT.md b/SUPPORT.md new file mode 100644 index 0000000..a0b297a --- /dev/null +++ b/SUPPORT.md @@ -0,0 +1,7 @@ +# Support + +Read the project's README, documentation and existing issues first. For reproducible bugs or feature requests, use the affected repository's issue templates when available. For general questions, use its Discussions area if enabled; otherwise follow its README support instructions. + +Community help is provided as maintainers are available and does not include a response-time commitment. For paid support or commercial licensing inquiries, contact hello@nightsquawk.tech. A paid software license includes only the support expressly stated in its agreement. + +Use SECURITY.md to report suspected vulnerabilities privately. Never post live credentials, personal information, customer data or unredacted diagnostic bundles in public support requests. diff --git a/automation/public_repo_drift.py b/automation/public_repo_drift.py new file mode 100644 index 0000000..7b3c5da --- /dev/null +++ b/automation/public_repo_drift.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python3 +"""Read-only public repository baseline audit; no credentials or alert payloads emitted.""" +import argparse, base64, concurrent.futures, datetime, json, re, subprocess +from pathlib import Path +from urllib.parse import quote + +def api(path,paginate=False): + args=['gh','api',path] + if paginate:args+=['--paginate','--slurp'] + p=subprocess.run(args,capture_output=True,text=True,timeout=60) + if p.returncode: + match=re.search(r'HTTP (\d+)',p.stderr) + return {'unavailable':match.group(1) if match else 'request-failed'} + try:value=json.loads(p.stdout) + except json.JSONDecodeError:return {'unavailable':'invalid-response'} + return [v for page in value for v in page] if paginate and isinstance(value,list) else value + +def audit(repo): + name=repo['full_name'];branch=repo['default_branch'];root='repos/'+name + result={'repository':name,'default_branch':branch,'drift':[],'unknown':[]} + rules=api(root+'/rules/branches/'+quote(branch,safe='')) + if isinstance(rules,list): + types={r['type'] for r in rules} + for required in ['deletion','non_fast_forward','pull_request']: + if required not in types:result['drift'].append('missing-default-rule:'+required) + if not any(r.get('type')=='pull_request' and r.get('parameters',{}).get('required_review_thread_resolution') for r in rules): + result['drift'].append('unresolved-review-threads-permitted') + else:result['unknown'].append('effective-branch-rules:'+rules['unavailable']) + sets=api(root+'/rulesets?includes_parents=true&per_page=100',True) + if isinstance(sets,list): + tag_sets=[s for s in sets if s.get('target')=='tag' and s.get('enforcement')=='active'] + protected=False + for ruleset in tag_sets: + detail=api(root+'/rulesets/'+str(ruleset['id'])) + if 'unavailable' in detail: + result['unknown'].append('tag-ruleset:'+detail['unavailable']);continue + included=detail.get('conditions',{}).get('ref_name',{}).get('include',[]) + excluded=detail.get('conditions',{}).get('ref_name',{}).get('exclude',[]) + types={r['type'] for r in detail.get('rules',[])} + if 'refs/tags/v*' in included and not excluded and {'update','deletion'}<=types:protected=True + if not protected:result['drift'].append('missing-version-tag-protection') + else:result['unknown'].append('tag-rulesets:'+sets['unavailable']) + tree=api(root+'/git/trees/'+quote(branch,safe='')+'?recursive=1') + if tree.get('truncated') or 'unavailable' in tree: + result['unknown'].append('workflow-tree-unavailable-or-truncated') + else: + for entry in tree.get('tree',[]): + path=entry['path'] + if entry.get('type')!='blob' or not path.startswith('.github/workflows/') or not path.endswith(('.yml','.yaml')):continue + blob=api(root+'/git/blobs/'+entry['sha']) + if 'unavailable' in blob: + result['unknown'].append('workflow-read:'+path);continue + body=base64.b64decode(blob.get('content','')).decode() + for match in re.finditer(r'(?m)^\s*-?\s*uses:\s*[\'\"]?([^\s\'\"#]+)',body): + action=match[1] + if action.startswith(('./','docker://')):continue + if not re.search(r'@[0-9a-f]{40}$',action):result['drift'].append('unpinned-workflow-reference:'+path) + return result + +def main(): + p=argparse.ArgumentParser(description=__doc__) + p.add_argument('--owners',nargs='+',default=['NightSquawk','Kvrnn']) + p.add_argument('--output',default='public-repo-drift.json') + args=p.parse_args();inventory=[];errors=[] + for owner in args.owners: + data=api('users/'+owner+'/repos?type=owner&per_page=100',True) + if not isinstance(data,list):errors.append(owner+':'+data['unavailable']);continue + inventory.extend(r for r in data if not r.get('private') and not r.get('archived') and r['owner']['login'].lower()==owner.lower()) + with concurrent.futures.ThreadPoolExecutor(max_workers=4) as pool:results=list(pool.map(audit,inventory)) + report={'observed_at_utc':datetime.datetime.now(datetime.timezone.utc).isoformat(),'scope':'Active public repositories; default-branch rules, version-tag rules and workflow SHA references only. Security feature/admin settings need an administrator audit.','inventory_errors':errors,'repositories':results} + Path(args.output).write_text(json.dumps(report,indent=2)+'\n') + for r in results:print(r['repository']+': '+str(len(r['drift']))+' drift, '+str(len(r['unknown']))+' unknown') + failed=bool(errors or any(r['drift'] or r['unknown'] for r in results)) + print('Baseline audit '+('requires attention' if failed else 'passed')+'; no settings were changed.') + return int(failed) + +if __name__=='__main__':raise SystemExit(main()) From 97bb8b047908d36c828580fe8a1ebbcbbfbeedf8 Mon Sep 17 00:00:00 2001 From: K <39208150+Kvrnn@users.noreply.github.com> Date: Mon, 9 Nov 2026 07:02:20 -0800 Subject: [PATCH 2/5] fix: preserve drift audit evidence on API failures and verify public access --- .github/workflows/public-repo-drift.yml | 8 ++++++++ automation/public_repo_drift.py | 13 +++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.github/workflows/public-repo-drift.yml b/.github/workflows/public-repo-drift.yml index a481438..716ac61 100644 --- a/.github/workflows/public-repo-drift.yml +++ b/.github/workflows/public-repo-drift.yml @@ -22,6 +22,14 @@ jobs: python-version: '3.12' - name: Check script syntax run: python -m py_compile automation/public_repo_drift.py + - name: Verify read-only access to public audit targets + env: + GH_TOKEN: ${{ github.token }} + run: | + gh api 'users/NightSquawk/repos?type=owner&per_page=100' --jq length + gh api repos/NightSquawk/mcp-core/rules/branches/v1.0.0 --jq length + gh api repos/Kvrnn/CodeTimer/rules/branches/main --jq length + gh api repos/Kvrnn/CodeTimer/git/trees/main --jq .sha - name: Audit public baseline if: github.event_name != 'pull_request' env: diff --git a/automation/public_repo_drift.py b/automation/public_repo_drift.py index 7b3c5da..4338d44 100644 --- a/automation/public_repo_drift.py +++ b/automation/public_repo_drift.py @@ -7,7 +7,12 @@ def api(path,paginate=False): args=['gh','api',path] if paginate:args+=['--paginate','--slurp'] - p=subprocess.run(args,capture_output=True,text=True,timeout=60) + try: + p=subprocess.run(args,capture_output=True,text=True,timeout=60) + except subprocess.TimeoutExpired: + return {'unavailable':'timeout'} + except OSError: + return {'unavailable':'client-unavailable'} if p.returncode: match=re.search(r'HTTP (\d+)',p.stderr) return {'unavailable':match.group(1) if match else 'request-failed'} @@ -66,7 +71,11 @@ def main(): data=api('users/'+owner+'/repos?type=owner&per_page=100',True) if not isinstance(data,list):errors.append(owner+':'+data['unavailable']);continue inventory.extend(r for r in data if not r.get('private') and not r.get('archived') and r['owner']['login'].lower()==owner.lower()) - with concurrent.futures.ThreadPoolExecutor(max_workers=4) as pool:results=list(pool.map(audit,inventory)) + def guarded_audit(repo): + try:return audit(repo) + except Exception: + return {'repository':repo['full_name'],'default_branch':repo['default_branch'],'drift':[],'unknown':['audit-error']} + with concurrent.futures.ThreadPoolExecutor(max_workers=4) as pool:results=list(pool.map(guarded_audit,inventory)) report={'observed_at_utc':datetime.datetime.now(datetime.timezone.utc).isoformat(),'scope':'Active public repositories; default-branch rules, version-tag rules and workflow SHA references only. Security feature/admin settings need an administrator audit.','inventory_errors':errors,'repositories':results} Path(args.output).write_text(json.dumps(report,indent=2)+'\n') for r in results:print(r['repository']+': '+str(len(r['drift']))+' drift, '+str(len(r['unknown']))+' unknown') From d3e30ffb11017b5c773ce470cf061e13f67a886f Mon Sep 17 00:00:00 2001 From: K <39208150+Kvrnn@users.noreply.github.com> Date: Mon, 9 Nov 2026 07:05:29 -0800 Subject: [PATCH 3/5] test: cover audit API failures and rule parsing --- .github/workflows/public-repo-drift.yml | 2 +- automation/public_repo_drift_test.py | 28 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 automation/public_repo_drift_test.py diff --git a/.github/workflows/public-repo-drift.yml b/.github/workflows/public-repo-drift.yml index 716ac61..8314266 100644 --- a/.github/workflows/public-repo-drift.yml +++ b/.github/workflows/public-repo-drift.yml @@ -21,7 +21,7 @@ jobs: with: python-version: '3.12' - name: Check script syntax - run: python -m py_compile automation/public_repo_drift.py + run: python -m unittest discover -s automation -p "*_test.py" -v - name: Verify read-only access to public audit targets env: GH_TOKEN: ${{ github.token }} diff --git a/automation/public_repo_drift_test.py b/automation/public_repo_drift_test.py new file mode 100644 index 0000000..4e3c67e --- /dev/null +++ b/automation/public_repo_drift_test.py @@ -0,0 +1,28 @@ +import subprocess +import unittest +from unittest.mock import patch +import public_repo_drift as audit + +class ApiEvidenceTests(unittest.TestCase): + def test_timeout_is_explicitly_unavailable(self): + with patch.object(audit.subprocess,'run',side_effect=subprocess.TimeoutExpired('gh',60)): + self.assertEqual(audit.api('repos/example/repo'),{'unavailable':'timeout'}) + + def test_http_error_does_not_become_zero_coverage(self): + response=subprocess.CompletedProcess(['gh'],1,stdout='',stderr='API read failed (HTTP 403)') + with patch.object(audit.subprocess,'run',return_value=response): + self.assertEqual(audit.api('repos/example/repo'),{'unavailable':'403'}) + + def test_thread_resolution_is_a_pull_request_parameter(self): + rules=[{'type':'deletion'},{'type':'non_fast_forward'}, + {'type':'pull_request','parameters':{'required_review_thread_resolution':True}}] + def response(path,paginate=False): + if '/rules/branches/' in path:return rules + if '/rulesets?' in path:return [] + return {'tree':[]} + with patch.object(audit,'api',side_effect=response): + result=audit.audit({'full_name':'example/repo','default_branch':'main'}) + self.assertNotIn('unresolved-review-threads-permitted',result['drift']) + self.assertIn('missing-version-tag-protection',result['drift']) + +if __name__=='__main__':unittest.main() From f5d4cb51e695e875bfd0425c2bc628196b3c4985 Mon Sep 17 00:00:00 2001 From: K <39208150+Kvrnn@users.noreply.github.com> Date: Mon, 9 Nov 2026 07:07:22 -0800 Subject: [PATCH 4/5] fix: parse workflow YAML and preserve scheduled audit evidence --- .github/dependabot.yml | 5 +++++ .github/workflows/public-repo-drift.yml | 5 ++++- automation/public_repo_drift.py | 21 ++++++++++++++++++--- automation/public_repo_drift_test.py | 21 +++++++++++++++++++++ automation/requirements.txt | 3 +++ 5 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 automation/requirements.txt diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 8004983..3c972b0 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,3 +5,8 @@ updates: schedule: interval: weekly open-pull-requests-limit: 5 + - package-ecosystem: pip + directory: /automation + schedule: + interval: weekly + open-pull-requests-limit: 5 diff --git a/.github/workflows/public-repo-drift.yml b/.github/workflows/public-repo-drift.yml index 8314266..6de7360 100644 --- a/.github/workflows/public-repo-drift.yml +++ b/.github/workflows/public-repo-drift.yml @@ -5,7 +5,7 @@ on: workflow_dispatch: pull_request: paths: - - automation/public_repo_drift.py + - automation/** - .github/workflows/public-repo-drift.yml permissions: contents: read @@ -20,9 +20,12 @@ jobs: - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7 with: python-version: '3.12' + - name: Install pinned audit parser + run: python -m pip install --require-hashes -r automation/requirements.txt - name: Check script syntax run: python -m unittest discover -s automation -p "*_test.py" -v - name: Verify read-only access to public audit targets + if: github.event_name == 'pull_request' env: GH_TOKEN: ${{ github.token }} run: | diff --git a/automation/public_repo_drift.py b/automation/public_repo_drift.py index 4338d44..86d51cc 100644 --- a/automation/public_repo_drift.py +++ b/automation/public_repo_drift.py @@ -3,6 +3,18 @@ import argparse, base64, concurrent.futures, datetime, json, re, subprocess from pathlib import Path from urllib.parse import quote +import yaml + +def action_references(body): + workflow=yaml.safe_load(body) + if not isinstance(workflow,dict):return [] + refs=[] + for job in workflow.get('jobs',{}).values(): + if not isinstance(job,dict):continue + if isinstance(job.get('uses'),str):refs.append(job['uses']) + for step in job.get('steps',[]): + if isinstance(step,dict) and isinstance(step.get('uses'),str):refs.append(step['uses']) + return refs def api(path,paginate=False): args=['gh','api',path] @@ -42,7 +54,8 @@ def audit(repo): included=detail.get('conditions',{}).get('ref_name',{}).get('include',[]) excluded=detail.get('conditions',{}).get('ref_name',{}).get('exclude',[]) types={r['type'] for r in detail.get('rules',[])} - if 'refs/tags/v*' in included and not excluded and {'update','deletion'}<=types:protected=True + covers_versions=any(p in included for p in ['refs/tags/v*','refs/tags/*','refs/tags/**','~ALL']) + if covers_versions and not excluded and {'update','deletion'}<=types:protected=True if not protected:result['drift'].append('missing-version-tag-protection') else:result['unknown'].append('tag-rulesets:'+sets['unavailable']) tree=api(root+'/git/trees/'+quote(branch,safe='')+'?recursive=1') @@ -56,8 +69,10 @@ def audit(repo): if 'unavailable' in blob: result['unknown'].append('workflow-read:'+path);continue body=base64.b64decode(blob.get('content','')).decode() - for match in re.finditer(r'(?m)^\s*-?\s*uses:\s*[\'\"]?([^\s\'\"#]+)',body): - action=match[1] + try:references=action_references(body) + except yaml.YAMLError: + result['unknown'].append('invalid-workflow-yaml:'+path);continue + for action in references: if action.startswith(('./','docker://')):continue if not re.search(r'@[0-9a-f]{40}$',action):result['drift'].append('unpinned-workflow-reference:'+path) return result diff --git a/automation/public_repo_drift_test.py b/automation/public_repo_drift_test.py index 4e3c67e..d42b8e5 100644 --- a/automation/public_repo_drift_test.py +++ b/automation/public_repo_drift_test.py @@ -25,4 +25,25 @@ def response(path,paginate=False): self.assertNotIn('unresolved-review-threads-permitted',result['drift']) self.assertIn('missing-version-tag-protection',result['drift']) + def test_flow_style_actions_are_found_without_matching_shell_text(self): + body='''jobs: + build: + steps: [{ uses: actions/checkout@v4 }] + shell: + steps: + - run: | + uses: not/an-action@v1 +''' + self.assertEqual(audit.action_references(body),['actions/checkout@v4']) + + def test_all_tag_protection_covers_version_tags(self): + def response(path,paginate=False): + if '/rules/branches/' in path:return [] + if '/rulesets?' in path:return [{'id':1,'target':'tag','enforcement':'active'}] + if '/rulesets/1' in path:return {'conditions':{'ref_name':{'include':['~ALL'],'exclude':[]}},'rules':[{'type':'update'},{'type':'deletion'}]} + return {'tree':[]} + with patch.object(audit,'api',side_effect=response): + result=audit.audit({'full_name':'example/repo','default_branch':'main'}) + self.assertNotIn('missing-version-tag-protection',result['drift']) + if __name__=='__main__':unittest.main() diff --git a/automation/requirements.txt b/automation/requirements.txt new file mode 100644 index 0000000..e72d484 --- /dev/null +++ b/automation/requirements.txt @@ -0,0 +1,3 @@ +PyYAML==6.0.3 \ + --hash=sha256:ba1cc08a7ccde2d2ec775841541641e4548226580ab850948cbfda66a1befcdc \ + --hash=sha256:d76623373421df22fb4cf8817020cbb7ef15c725b9d5e45f17e189bfc384190f From 7fe600bf6f7c4d53569e149447b4cd4567c6216d Mon Sep 17 00:00:00 2001 From: K <39208150+Kvrnn@users.noreply.github.com> Date: Mon, 9 Nov 2026 07:17:07 -0800 Subject: [PATCH 5/5] fix: combine tag protections and use direct private reporting --- .github/ISSUE_TEMPLATE/config.yml | 2 +- automation/public_repo_drift.py | 18 +++++++++++++++--- automation/public_repo_drift_test.py | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 88157c3..42aadfe 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,5 +1,5 @@ blank_issues_enabled: false contact_links: - name: Private security report - url: https://github.com/NightSquawk/.github/blob/v1.0.0/SECURITY.md + url: https://github.com/NightSquawk/.github/security/advisories/new about: Follow the private reporting instructions; do not publish vulnerability details here. diff --git a/automation/public_repo_drift.py b/automation/public_repo_drift.py index 86d51cc..4a1b572 100644 --- a/automation/public_repo_drift.py +++ b/automation/public_repo_drift.py @@ -16,6 +16,12 @@ def action_references(body): if isinstance(step,dict) and isinstance(step.get('uses'),str):refs.append(step['uses']) return refs +def may_exclude_version_tags(pattern): + if pattern=='~ALL':return True + literal=re.split(r'[*?\[]',pattern,maxsplit=1)[0] + version_prefix='refs/tags/v' + return version_prefix.startswith(literal) or literal.startswith(version_prefix) + def api(path,paginate=False): args=['gh','api',path] if paginate:args+=['--paginate','--slurp'] @@ -46,7 +52,8 @@ def audit(repo): sets=api(root+'/rulesets?includes_parents=true&per_page=100',True) if isinstance(sets,list): tag_sets=[s for s in sets if s.get('target')=='tag' and s.get('enforcement')=='active'] - protected=False + effective_tag_rules=set() + uncertain_tag_conditions=False for ruleset in tag_sets: detail=api(root+'/rulesets/'+str(ruleset['id'])) if 'unavailable' in detail: @@ -55,8 +62,13 @@ def audit(repo): excluded=detail.get('conditions',{}).get('ref_name',{}).get('exclude',[]) types={r['type'] for r in detail.get('rules',[])} covers_versions=any(p in included for p in ['refs/tags/v*','refs/tags/*','refs/tags/**','~ALL']) - if covers_versions and not excluded and {'update','deletion'}<=types:protected=True - if not protected:result['drift'].append('missing-version-tag-protection') + if covers_versions: + if any(may_exclude_version_tags(p) for p in excluded): + uncertain_tag_conditions=True + else:effective_tag_rules.update(types) + if not {'update','deletion'}<=effective_tag_rules: + if uncertain_tag_conditions:result['unknown'].append('version-tag-exclusions-need-review') + else:result['drift'].append('missing-version-tag-protection') else:result['unknown'].append('tag-rulesets:'+sets['unavailable']) tree=api(root+'/git/trees/'+quote(branch,safe='')+'?recursive=1') if tree.get('truncated') or 'unavailable' in tree: diff --git a/automation/public_repo_drift_test.py b/automation/public_repo_drift_test.py index d42b8e5..017745c 100644 --- a/automation/public_repo_drift_test.py +++ b/automation/public_repo_drift_test.py @@ -46,4 +46,18 @@ def response(path,paginate=False): result=audit.audit({'full_name':'example/repo','default_branch':'main'}) self.assertNotIn('missing-version-tag-protection',result['drift']) + def test_non_version_exclusions_do_not_remove_version_protection(self): + self.assertFalse(audit.may_exclude_version_tags('refs/tags/test-*')) + self.assertTrue(audit.may_exclude_version_tags('refs/tags/v1.*')) + + def test_tag_rules_are_combined_across_matching_rulesets(self): + def response(path,paginate=False): + if '/rules/branches/' in path:return [] + if '/rulesets?' in path:return [{'id':n,'target':'tag','enforcement':'active'} for n in [1,2]] + if '/rulesets/' in path:return {'conditions':{'ref_name':{'include':['~ALL'],'exclude':['refs/tags/test-*']}},'rules':[{'type':'update' if path.endswith('/1') else 'deletion'}]} + return {'tree':[]} + with patch.object(audit,'api',side_effect=response): + result=audit.audit({'full_name':'example/repo','default_branch':'main'}) + self.assertNotIn('missing-version-tag-protection',result['drift']) + if __name__=='__main__':unittest.main()