Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any PR with "dangerous" edits should be considered dangerous #2985

Closed
peterbe opened this issue Mar 9, 2021 · 9 comments · Fixed by #3200
Closed

Any PR with "dangerous" edits should be considered dangerous #2985

peterbe opened this issue Mar 9, 2021 · 9 comments · Fixed by #3200
Assignees

Comments

@peterbe
Copy link
Contributor

peterbe commented Mar 9, 2021

Security scenario: Someone makes a PR that covers lots and lots of files. They might all look like harmless typo fixes in various index.html files. But they could also try to sneak in a change to .github/workflows/pr-testing.yml that disables something in the workflow that checks for unsafe things. For example:

-         export BUILD_FLAW_LEVELS="*:ignore, unsafe_html: error"
+         export BUILD_FLAW_LEVELS="*:ignore, unsafe_html: ignore"

Another example is that they might mess with yarn.lock so that it changes something like this:

-camelcase@^2.0.0:
   version "2.1.1"
-  resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-2.1.1.tgz#7c1d16d679a1bbe59ca02cacecfb011e201f5a1f"
   integrity sha1-fB0W1nmhu+WcoCys7PsBHiAfWh8=
+camelcese@^2.0.0:
   version "2.1.1"
+  resolved "https://registry.notyarnpkg.com/camelcase/-/camelcase-2.1.1.tgz#7c1d16d679a1bbe59ca02cacecfb011e201f5a1f"
   integrity sha1-fB0W1nmhu+WcoCys7PsBHiAfWh8=

If this happens, the reviewer should be as helped as possible to avoid missing this. Probably safest to just break the build so that only an admin can merge it. The hope and assumption is that seeing the red X on the checks should alert even the admins to not be too quick to merge.

@peterbe peterbe added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Mar 9, 2021
@peterbe
Copy link
Contributor Author

peterbe commented Mar 9, 2021

We'll need to assume that when dependabot[bot] makes PRs (for example #2979 or #2770) that they're OK and safe.
Note, for dependabot, they have write access to the repo so they push their branches to mdn/content instead of a fork. So instead of looking for username === 'dependabot' we can make the checking depend on it coming from a fork.

@peterbe
Copy link
Contributor Author

peterbe commented Mar 9, 2021

@nschonni Do you have some ideas for implementation here? I was thinking something like this:

name: Markdown Docs files

on:
  pull_request:
    paths:
      - scripts/*
      - package.json
      - yarn.lock
      - .github/workflows/*
jobs:
  checks:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - name: Stop anything
         run: |
           echo "Any PR that edits these files should break the build and expect admin overrides"
           exit 1

Do you have any good suggestions for checking if it's coming from a fork or not? (...to solve the problem of letting dependabot PRs roll)

@peterbe
Copy link
Contributor Author

peterbe commented Mar 9, 2021

Would it be an option to write a workflow if: statement that checks if the PR submitter is an admin?

@peterbe
Copy link
Contributor Author

peterbe commented Mar 9, 2021

We have to remember to do the same with mdn/translated-content: mdn/translated-content#91

@nschonni
Copy link
Contributor

nschonni commented Mar 9, 2021

GitHub does something like this for their docs in https://github.com/github/docs/blob/main/.github/workflows/triage-unallowed-contributions.yml but I'm not sure I always like that approach (stopped contributing their since they just auto-close CI related PRs 😝 )

I'm not sure if there is anything else needed to make it "enforce" the values you've already set in the CODEOWNERS

Would it be an option to write a workflow if: statement that checks if the PR submitter is an admin?

Think there are some examples of that in the GitHub/docs jobs too

@peterbe
Copy link
Contributor Author

peterbe commented Mar 9, 2021

@nschonni Auto-closing PRs seems a bit draconian. There are many pieces I don't quite understand what that does.
We can start with not auto-closing, but at least exit non-zero and then slowly crawl back to a state where it's convenient and sufficiently safe for us. We still need to be able to have amazing contributors like yourself make PRs to workflows and stuff.

@peterbe peterbe self-assigned this Mar 16, 2021
peterbe added a commit to peterbe/content that referenced this issue Mar 16, 2021
peterbe added a commit that referenced this issue Mar 18, 2021
* Any PR with "dangerous" edits should be considered dangerous

Fixes #2985

* try again

* no need for it being a pull_request_target

* only on mdn/content

* repository_owner

* repository_owner

* dbg

* must be pull_request_target

* comment out

* more small edits

* rename
@peterbe
Copy link
Contributor Author

peterbe commented Mar 18, 2021

Oops. #3200 does not fix this issue yet.
I merged it in (without review) so I can see what it does.

@peterbe peterbe reopened this Mar 18, 2021
@peterbe peterbe removed the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Mar 18, 2021
@peterbe
Copy link
Contributor Author

peterbe commented Mar 30, 2021

This is "in production" now.

@peterbe peterbe closed this as completed Mar 30, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants