Commit 8e5f2b3
authored
fix: sanitize the branch name returned by the github api (#43)
The remaining tssecurity:S8476 flow is a different one from the two fixed
in #42: its source is not user input but the GitHub API response itself.
`fetchDefaultBranch` trusted `data.default_branch` verbatim and that
value flows straight back into the trees and contents request URLs, so a
compromised or unexpected response could steer them.
`default_branch` now goes through the same `sanitizeBranch` ref check as
user input and falls back to 'main' when it fails. `fetchFile` sanitizes
its branch argument too, so all three request builders agree instead of
`fetchTree` being the only one that checked.
Verified with the real module and fetch stubbed to answer the repo lookup
with default_branch of "../../../evil?x=": 8 requests issued, 0 escaping
the /repos/<owner>/<repo> path, tree call falls back to main.1 parent 6423ede commit 8e5f2b3
1 file changed
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
147 | | - | |
| 147 | + | |
| 148 | + | |
148 | 149 | | |
149 | 150 | | |
150 | 151 | | |
| |||
177 | 178 | | |
178 | 179 | | |
179 | 180 | | |
180 | | - | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
181 | 185 | | |
182 | 186 | | |
183 | 187 | | |
| |||
0 commit comments