Your source control platform decides what code reaches production, so anyone who can push to a protected branch, change a review rule or steal a token from it can ship their code through your own pipeline. The platform holds source code, infrastructure definitions, pipeline configuration and often secrets that should never have been committed. It is also crowded with non-human identities: personal access tokens, deploy keys, integration apps, OAuth apps, webhooks and CI tokens. This guide is for platform engineering, DevSecOps and security teams who run a hosted or self-managed source control platform. It covers the attack surface, organisation and repository admin roles, the tokens and integrations that act on the platform, branch and review protections, logging, hardening and decommissioning. It is vendor-neutral, so confirm exact setting names in your vendor's documentation. For repository-level practice, see the Git Repository Security Guide; for secrets in code, the Git Secret Scanning Guide.
Key takeaways
- Treat the platform as tier 0 for software delivery. Organisation owners and the identities that can bypass branch protection can change what every pipeline builds.
- Enforce SSO and phishing-resistant MFA for every human. Then remove long-lived personal tokens wherever a federated or app-based identity can do the job.
- Inventory every machine identity. Tokens, deploy keys, apps, OAuth apps and webhooks each need an owner, the narrowest scope and an expiry.
- Make branch protection something admins cannot quietly skip. Require review by someone other than the author on protected branches, apply rules to administrators too, and alert on every rule change.
- Stream the platform audit log out on day one. Rule changes, token creation, repository visibility changes and bulk clones are what investigations need.
What makes up a source control platform's attack surface
The OWASP Top 10 CI/CD Security Risks puts Insufficient Flow Control Mechanisms (CICD-SEC-1), Inadequate Identity and Access Management (CICD-SEC-2), Insufficient Credential Hygiene (CICD-SEC-6), Insecure System Configuration (CICD-SEC-7), Ungoverned Usage of 3rd Party Services (CICD-SEC-8) and Insufficient Logging and Visibility (CICD-SEC-10) on the list, and all of them land on the source control platform. NIST SP 800-218 (SSDF 1.1) asks producers to protect all forms of code from unauthorised access and tampering. The table reflects a common architecture and is NHI Mgmt Group's view; your platform may name, merge or split these components differently.
| Component | What it holds or does | If an attacker controls it | Primary control |
|---|---|---|---|
| Organisation or instance administration | Members, SSO, policies, rules, integrations, visibility settings | Disables protections, adds members, makes private code public | Few owners, just-in-time elevation, alerting on policy change |
| Repositories and branches | Source, infrastructure code, pipeline definitions | Pushes malicious code or pipeline changes (T1195.002) | Branch protection, required review, signed commits where used |
| Personal access tokens and SSH keys | Act as the user from scripts and laptops | Clones every repository the user can read (T1213.003) | Fine-grained, expiring tokens; SSO enforcement on tokens; key inventory |
| Deploy keys and machine users | Per-repository or shared automation access | Write access that bypasses human controls | Read-only by default, owner and expiry, replace machine users with apps |
| Installed apps and OAuth apps | Third-party and internal integrations with scoped permissions | Steals the app token or abuses broad scopes (T1528, T1199) | Admin approval for installs, least scopes, periodic review |
| Webhooks | Push events, sometimes with code content, to external URLs | Redirects events to an attacker endpoint | Webhook secrets, TLS, alert on new or changed webhooks |
| CI integration and runners | Tokens the pipeline uses to read code and publish results | Poisoned pipeline execution (CICD-SEC-4) and secret theft | Short-lived job tokens, protected branch conditions |
Administrative roles and separation of duties
- Organisation owners: keep to a small named group with just-in-time elevation where the platform or your PAM tool supports it. Owners should not use the same account for daily development.
- Repository administrators: repository admins can often change branch protection for their repository. Grant admin to a platform or security team, and give development teams maintain or write roles.
- Rules set above the repository: where the platform supports organisation-level rules or rulesets, define branch protection centrally so that a repository admin cannot weaken it for one repository.
- Bypass lists: any role, team or app allowed to bypass protection is equivalent to an owner for that branch. Keep bypass lists empty by default and review them every quarter (our recommendation).
- Outside collaborators and contractors: give them repository-level access through named accounts under your SSO where possible, with an end date, and never organisation membership by default.
- Self-managed instances: separate instance administrators (server, storage, backups) from organisation owners, and administer servers only from privileged access workstations, in line with the NCSC secure system administration principles. See the Privileged Access Workstations Guide.
Authentication for people
- SSO everywhere: enforce SSO through your identity provider so leavers lose access when their identity is disabled. The CISA and FBI Secure by Demand guide asks whether standards-based SSO is supported at no additional cost.
- Phishing-resistant MFA: require it at the identity provider and, where the platform supports it, require MFA for platform-local accounts too. Keep one documented break-glass owner account. See the Break-Glass Account Guide.
- Git over SSH and HTTPS: Git operations often bypass the web sign-in. Require tokens and SSH keys to be authorised for SSO, prefer SSH certificates or hardware-backed keys where supported, and expire keys. See the SSH Key Management Guide.
- IP and device conditions: where offered, restrict platform access for the organisation to corporate networks or compliant devices, and apply the same to tokens.
Tokens, keys, apps and other machine identities
Most incidents involving source control start with a credential, not an exploit. The SLSA v1.2 Source track (status Approved, checked November 2026) lists stronger authentication, including phishing-resistant factors and forbidding bearer tokens such as personal access tokens, as a future consideration rather than a current requirement, so you have to set the bar yourself.
| Identity | Use it for | Avoid | Pattern |
|---|---|---|---|
| Personal access token | A developer's own scripted work | Production automation; tokens with no expiry; organisation-wide write scopes | Fine-grained, single-repository where possible, maximum lifetime set by policy, admin approval for organisation access |
| Deploy key | One server reading one repository | Write access; one key reused across repositories | Read-only, one per repository and consumer, owner recorded |
| Machine user (bot account) | Legacy automation only | Shared passwords; membership of owner groups | Replace with an app identity; until then, SSO, MFA where possible and a named owner |
| Installed app | Integrations and internal automation | Installing on all repositories; administration or member-management permissions | Selected repositories, least permissions, short-lived installation tokens |
| OAuth app | Third-party tools acting as a user | Broad scopes granted by any user without review | Organisation approval required, review scopes, revoke unused |
| CI job token | The running pipeline reading code and writing results | Default write permissions to the repository | Read-only by default, write only in named jobs, federation to clouds instead of stored keys |
- Inventory and owners: export every token, key, app and webhook, map each to an owner and purpose, and record them in your NHI inventory. See the Service Account Security Guide.
- Federation for pipelines: let CI jobs obtain short-lived cloud credentials through workload identity federation, scoped to repository and branch, instead of storing cloud keys in the platform. See the Workload Identity Federation Guide.
- Third-party governance: require admin approval for app and OAuth app installs and review them every quarter. See the SaaS and OAuth App Governance Guide.
- Secrets in code: turn on secret scanning and push protection where the platform offers it, and treat any secret found as compromised. See Private Keys in Repositories Guide and Securing the secrets scanning tool itself.
Branch protection, review and integrity
SLSA v1.2 Source Level 2 requires that branch history be continuous, immutable and retained; Level 3 requires the platform to enforce the organisation's technical controls on named references; Level 4 requires that changes to protected branches be agreed by two or more trusted persons before submission. Use those levels as a maturity path.
- Protect default and release branches: block force pushes and deletion, require pull or merge requests, and require status checks to pass.
- Require independent review: at least one approval from someone other than the author, dismiss stale approvals when new commits are pushed, and require code owner review for sensitive paths such as pipeline definitions, infrastructure code and access configuration. See the Secure Code Review Guide.
- Include administrators: apply rules to owners and admins, and route emergency bypasses through break-glass with an alert.
- Protect tags: restrict who can create or move release tags, because many pipelines release on tag.
- Commit signing where it adds value: require signed commits on protected branches if your verifiers will check them, and manage signing keys like any other credential. See the Sigstore Guide.
- Pipeline definitions are code: changes to pipeline files and to who can trigger workflows from forks need the same review as application code. See the CI/CD Security Guide.
Logging and detection
Stream the platform audit log, and Git event logs where available, to your SIEM and to storage outside the platform admins' control. Check how long the platform keeps logs; Secure by Demand asks that cloud services keep security logs for at least six months at no extra charge. NIST SP 800-53 AU-9(2) covers storing audit records on a separate system.
| Event | Why it matters | Alert |
|---|---|---|
| Branch protection or ruleset changed or deleted; bypass list changed | Opens the path to unreviewed code (CICD-SEC-1) | Always |
| Repository made public, transferred or archived | Code or secret exposure; disruption | Always |
| New owner, new outside collaborator, SSO setting changed | Persistence (T1098) | Always |
| Token, deploy key or SSH key created; app installed or scopes increased | New credential or integration (T1098.001) | Outside a change, or with write or admin scopes |
| Bulk clone or archive download by one identity | Code theft (T1213.003) | Above a per-identity baseline |
| Token used from a new network or country | Stolen token (T1528) | For machine identities, any change of origin |
| Webhook created or its URL changed | Event and code redirection | Always |
| Audit log streaming disabled | Blind spot (T1685) | Always, from a separate channel |
Hardening an existing platform: a phased approach
- Turn on audit log streaming and the alerts above before changing access, so you can see breakage and misuse.
- Inventory: owners, admins, outside collaborators, tokens, keys, apps, OAuth apps, webhooks and bypass lists. Flag tokens without expiry and apps installed on all repositories.
- Enforce SSO and MFA for the organisation, with a grace period and a list of accounts that will fail.
- Apply branch rules in evaluate or audit mode where the platform offers it, review what would have been blocked for two weeks, then enforce, starting with a pilot group of repositories.
- Set token policy: maximum lifetime, approval for organisation access, then expire legacy tokens in waves with owner notice.
- Roll back safely: keep previous rules exported as code. If a release is blocked, grant a time-boxed bypass through break-glass and fix the rule, rather than deleting protection.
Decision guidance
| Decision | Option A fits when | Option B fits when |
|---|---|---|
| Hosted service (A) or self-managed instance (B) | You want the vendor to patch and run the platform; confirm SSO, audit log streaming and data residency | Network isolation or data residency rules need it; you can patch promptly and protect the server, storage and backups |
| Personal tokens (A) or app identities (B) for automation | Short-lived, single-developer scripts | Anything shared, long-running or production; app identities survive staff departures |
| One review (A) or two-party review plus code owners (B) | Low-risk repositories with strong CI checks | Repositories that build production, infrastructure or pipeline code |
Small teams should at least enforce SSO and MFA, protect default branches including for admins, set token expiry and stream the audit log. Large organisations add central rulesets, code owners, app-only automation and per-identity clone baselines.
Lifecycle of the platform
- Buy: ask the Secure by Demand questions (SSO at no extra cost, MFA by default, logging in the base product, at least six months of log retention for cloud services, a vulnerability disclosure policy, an SBOM) and whether rules can be enforced for administrators.
- Run: apply vendor security updates promptly for self-managed instances and subscribe to the vendor's security advisories page; review owners, bypass lists, tokens and apps every quarter; track the Source control platform health check metrics.
- Back up: back up repositories, including metadata such as issues and rules, to storage the platform admins cannot delete, and test a restore. See the Backup Security and Immutable Backup Guide.
- Migrate or retire: reissue every token, deploy key, app credential and webhook secret on the new platform rather than copying them, re-create rules before importing code, then revoke all credentials on the old platform and confirm data deletion. See the Source control platform migration playbook.
Detection and measurement
- Percentage of human members signing in through SSO with phishing-resistant MFA (target: 100%).
- Number of organisation owners (target: five or fewer, our suggestion) and number of identities on any bypass list.
- Percentage of production repositories with protected default branches that include administrators and require independent review.
- Personal access tokens without expiry or older than policy (target: zero).
- Apps and OAuth apps with write or admin scopes and no review in the last quarter (target: zero).
- Median time to revoke a leaked token after a secret scanning alert.
Framework mapping
| Control area | NIST SP 800-53 Rev. 5 | NIST CSF 2.0 | ATT&CK threat addressed |
|---|---|---|---|
| Admin roles and bypass control | AC-5, AC-6, AC-6(5), CM-5 | PR.AA-05 | T1098 Account Manipulation |
| Human and token authentication | IA-5, AC-2 | PR.AA-01 | T1078 Valid Accounts, T1528 Steal Application Access Token |
| Branch protection and review | CM-3, SR-3 | PR.PS-06 | T1195.002 Compromise Software Supply Chain |
| Third-party apps | SA-9 | GV.SC-07 | T1199 Trusted Relationship |
| Code and secret protection | AC-6, SC-28 | PR.DS-01 | T1213.003 Code Repositories, T1552.001 Credentials In Files |
| Audit logging | AU-6, AU-9(2), AC-6(9) | PR.PS-04 | T1685 Disable or Modify Tools |
| Backups | CP-9 | PR.DS-11 | T1485 Data Destruction |
In ISO/IEC 27001:2022 Annex A, see 8.4 Access to source code, 8.32 Change management, 8.2 Privileged access rights and 8.15 Logging. In NIST SP 800-218, the main practice is PS.1, protecting all forms of code from unauthorised access and tampering.
Common failure patterns
- Rules that exempt admins: branch protection is on, but owners and repository admins can push directly, so one stolen admin token skips review.
- Tokens that never expire: a personal token created years ago for a build script still has organisation-wide write access after its owner has left.
- Apps installed on everything: an integration needed for three repositories is installed on all of them with write permissions.
- Machine users in owner groups: a bot account added as owner to fix a permissions error, with a shared password and no MFA.
- Pipeline files outside review: application code needs code owner approval but pipeline definitions do not, so an attacker edits the pipeline instead.
- Audit log kept only in the platform: default retention expires before an investigation starts.
Practitioner checklist
- Classify organisation owners, rule bypass identities and the platform's admin plane as tier 0.
- Enforce SSO with phishing-resistant MFA for all members and keep one tested break-glass owner.
- Define branch protection centrally, include administrators, and keep bypass lists empty by default.
- Require independent review and code owner approval for pipeline, infrastructure and access configuration files.
- Set a maximum token lifetime, require approval for organisation access and expire legacy tokens.
- Replace machine users and shared tokens with app identities scoped to selected repositories.
- Use federation for CI access to clouds instead of stored keys.
- Require admin approval for app and OAuth app installs and review them quarterly.
- Stream the audit log to your SIEM and to immutable storage, and alert on rule, visibility and token changes.
- Back up repositories and metadata outside the platform and test a restore.
Standards and references
- NIST: SP 800-218 Secure Software Development Framework (SSDF) Version 1.1
- OpenSSF SLSA: v1.2 Source Track Requirements
- OWASP: Top 10 CI/CD Security Risks
- NIST: SP 800-53 Rev. 5 Security and Privacy Controls
- NCSC: Secure system administration
- CISA and FBI: Secure by Demand Guide
- MITRE ATT&CK: T1213.003 Code Repositories
- MITRE ATT&CK: T1195.002 Compromise Software Supply Chain
Related NHI Mgmt Group resources: Git Repository Security Guide · Git Secret Scanning Guide · Source control platform health check · Software Supply Chain Security Guide · CI/CD Pipeline Identity Security Guide