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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @motif-ui/core-team
File renamed without changes.
23 changes: 5 additions & 18 deletions .github/workflows/pr-validator.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "PR Validator"
name: PR Validator

on:
pull_request_target:
pull_request:
types: [opened, edited, reopened, synchronize]

concurrency:
Expand Down Expand Up @@ -31,20 +31,7 @@ jobs:
with:
pr-author: ${{ github.event.pull_request.user.login }}

# 2. CHECK FOR WORKFLOW CHANGES
- name: Get changed workflow files
id: changed-files
uses: tj-actions/changed-files@v44
with:
files: .github/workflows/**

- name: Security β€” Block unauthorized workflow changes
if: steps.changed-files.outputs.any_changed == 'true' && steps.team-check.outputs.is-internal != 'true'
run: |
echo "❌ Access Denied: Only core team members can modify workflow files."
exit 1

# 3. LINT PR TITLE
# 2. LINT PR TITLE
- name: Validate PR title
uses: amannn/action-semantic-pull-request@v5
env:
Expand All @@ -64,7 +51,7 @@ jobs:
revert
requireScope: false

# 4. SYNC RELEASE LABELS
# 3. SYNC RELEASE LABELS
- name: Sync release labels
uses: actions/github-script@v7
with:
Expand Down Expand Up @@ -103,7 +90,7 @@ jobs:
});
}

# 5. CHECK INTERNAL ISSUE REFERENCE
# 4. CHECK INTERNAL ISSUE REFERENCE
- name: Check internal issue reference
if: steps.team-check.outputs.is-internal == 'true'
uses: actions/github-script@v7
Expand Down
71 changes: 71 additions & 0 deletions .github/workflows/workflow-protection.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: "Workflow Protection"

on:
pull_request_target:
types: [opened, synchronize, reopened]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

permissions:
contents: read
pull-requests: read

jobs:
protect:
name: Detect Workflow Tampering
runs-on: ubuntu-latest
steps:

- name: Check for unauthorized .github/ changes
uses: actions/github-script@v7
with:
script: |
let page = 1;
let allFiles = [];
while (true) {
const { data: files } = await github.rest.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
per_page: 100,
Comment thread
aktasmehmet marked this conversation as resolved.
Resolved
page,
});
allFiles = allFiles.concat(files);
if (files.length < 100) break;
page++;
}

const sensitiveFiles = allFiles.filter(f =>
f.filename.startsWith('.github/workflows/') ||
f.filename.startsWith('.github/actions/')
);

if (sensitiveFiles.length === 0) {
core.info('No workflow or action files changed. βœ…');
return;
}

// 2. Check if the PR author is an authorized collaborator
let authorized = false;
try {
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: context.payload.pull_request.user.login,
});
authorized = ['admin', 'maintain', 'write'].includes(data.role_name);
} catch {
authorized = false;
}

if (!authorized) {
const changed = sensitiveFiles.map(f => ` - ${f.filename}`).join('\n');
core.setFailed(
`❌ This PR modifies protected files and the author is not an authorized collaborator.\n` +
`Changed files:\n${changed}`
);
} else {
core.info(`Authorized collaborator modifying .github/ files. βœ…`);
}
Loading