Skip to content

Commit c3b7a7a

Browse files
committed
Verify git checkout path is in site directory
This is unlikely, as we verify inputs come from GitHub using signatures, but it's best to be safe about this.
1 parent 61de8b0 commit c3b7a7a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

webhook.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,14 @@ async def github_webhook(request: web.Request):
156156
delivery, ref, expected_branch)
157157
return web.Response(status=200)
158158

159-
checkout = Path(os.environ.get('SITE_DIR', 'sites'), repository)
159+
site_dir = Path(os.environ.get('SITE_DIR', 'sites'))
160+
checkout = (site_dir / repository).resolve()
161+
if not checkout.is_relative_to(site_dir):
162+
raise web.HTTPBadRequest(
163+
reason=(f'{delivery}: Checkout for {organization}/{repository} '
164+
'does not exist'))
160165
if not (checkout / '.git').is_dir():
161-
raise web.HTTPInternalServerError(
166+
raise web.HTTPBadRequest(
162167
reason=(f'{delivery}: Checkout for {organization}/{repository} '
163168
'does not exist'))
164169
task = asyncio.create_task(

0 commit comments

Comments
 (0)