Repository navigation
Prevent release-tag injection in docs deployment #1
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
Open
sbillig
wants to merge
2
commits into
main
Choose a base branch
from
fix/deploy-tag-injection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| .build-cache/ | ||
| _build | ||
| __pycache__/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import gzip | ||
| import json | ||
| import shutil | ||
| import subprocess | ||
| import tempfile | ||
| import unittest | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| ROOT = Path(__file__).resolve().parents[1] | ||
|
|
||
|
|
||
| class DeployTests(unittest.TestCase): | ||
| def setUp(self): | ||
| self.temp = tempfile.TemporaryDirectory() | ||
| self.addCleanup(self.temp.cleanup) | ||
| self.site = Path(self.temp.name) | ||
| shutil.copy2(ROOT / "Makefile", self.site / "Makefile") | ||
| shutil.copytree(ROOT / "_template", self.site / "_template") | ||
| (self.site / "versions.json").write_text('{"latest":"","versions":[]}') | ||
| self.output = self.site / "output" | ||
| self.output.mkdir() | ||
| (self.output / "docs.json").write_text('{"index":{}}') | ||
| for name in ("fe-web.js", "fe-highlight.css", "styles.css"): | ||
| (self.output / name).write_text(name) | ||
|
|
||
| def make(self, target, variable): | ||
| return subprocess.run( | ||
| ["make", target, variable, f"OUTDIR={self.output}"], | ||
| cwd=self.site, | ||
| capture_output=True, | ||
| text=True, | ||
| check=False, | ||
| ) | ||
|
|
||
| def test_deploys_stable_and_prerelease_versions(self): | ||
| for version in ("26.3.0", "26.3.1-alpha.2"): | ||
| with self.subTest(version=version): | ||
| result = self.make("deploy", f"VERSION={version}") | ||
| self.assertEqual(result.returncode, 0, result.stderr) | ||
| with gzip.open(self.site / version / "docs.json.gz", "rt") as docs: | ||
| self.assertEqual(json.load(docs), {"index": {}}) | ||
| self.assertIn(version, (self.site / version / "index.html").read_text()) | ||
| versions = json.loads((self.site / "versions.json").read_text()) | ||
| self.assertEqual(versions["latest"], "26.3.0") | ||
| self.assertEqual(versions["versions"], ["26.3.0", "26.3.1-alpha.2"]) | ||
|
|
||
| def test_rejects_make_and_shell_substitution(self): | ||
| marker = self.site / "executed" | ||
| for payload in ( | ||
| f"26.3.0$(shell touch {marker})", | ||
| f"26.3.0$(touch {marker})", | ||
| "../escape", | ||
| ): | ||
| with self.subTest(payload=payload): | ||
| result = self.make("deploy", f"VERSION={payload}") | ||
| self.assertNotEqual(result.returncode, 0) | ||
| self.assertFalse(marker.exists()) | ||
|
|
||
| def test_rejects_unsafe_tag_before_building(self): | ||
| marker = self.site / "executed" | ||
| tag = f"v26.3.0$(shell touch {marker})" | ||
| for target, variable in (("build", f"TAG={tag}"), ("_build-tag", f"T={tag}")): | ||
| with self.subTest(target=target): | ||
| result = subprocess.run( | ||
| ["make", target, variable, f"FE_SRC={self.site}"], | ||
| cwd=self.site, | ||
| capture_output=True, | ||
| text=True, | ||
| check=False, | ||
| ) | ||
| self.assertNotEqual(result.returncode, 0) | ||
| self.assertFalse(marker.exists()) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
versions.jsonhas no stable versions, deploying a permitted prerelease or build-metadata version fails here withCannot index array with string "versions". After the inner pipeline reacheslast, the fallback.versions[0]is evaluated against that pipeline's array rather than the root object, so the command exits after creating the version artifacts but leavesversions.jsonunchanged. The new test misses this because it always deploys a stable version before the prerelease.Useful? React with 👍 / 👎.