Skip to content

Commit ebc8d50

Browse files
committed
fix: CWE-116 and CWE-79
closes #15
1 parent 8844ac2 commit ebc8d50

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

Dockerfile

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
FROM python:3.12.4-slim
1+
ARG PYTHON_VERSION=3.12.4-slim
2+
3+
FROM python:${PYTHON_VERSION}
24

3-
# LABELS
45
LABEL maintainer="Iván Alejandro Marugán <hello@ialejandro.rocks>" \
5-
description="Bitbucket Bot for Google Chat" \
6-
version="1.0.0"
6+
description="Bitbucket Bot for Google Chat"
77

8-
# APPLICATION
98
COPY app /app
109
COPY requirements.txt /requirements.txt
1110

12-
# INSTALL REQUIREMENTS
1311
RUN pip install -r /requirements.txt
1412

1513
WORKDIR /app
1614

17-
# RUN APP
1815
ENTRYPOINT ["gunicorn", "run:app"]

app/app.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import html
12
import json
23
import os
34
import requests
5+
46
from flask import Flask, request
57

68

@@ -188,12 +190,12 @@ def main():
188190
token = os.environ.get('TOKEN')
189191

190192
if request.args['token']!= token:
191-
exit(1)
193+
return "Invalid token", 403
192194

193195
event = request.get_json()
194196

195197
if not event:
196-
return "event empty"
198+
return "event empty", 400
197199

198200
message = Message(url, event)
199201
if (event['eventKey'] == 'pr:opened' or event['eventKey'] == 'pr:merged' or event['eventKey'] == 'pr:declined'):
@@ -208,6 +210,10 @@ def main():
208210
comment = message.pr_approved(event)
209211
r = message.send_message(comment)
210212

213+
# Mitigate XSS
214+
if isinstance(r, str):
215+
r = html.escape(r)
216+
211217
return r
212218

213219

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "bitbucket-bot",
3+
"version": "v1.0.0",
4+
"release": {
5+
"branches": [
6+
"main"
7+
],
8+
"repositoryUrl": "https://github.com/devops-ia/bitbucket-bot.git",
9+
"plugins": [
10+
"@semantic-release/release-notes-generator",
11+
"@semantic-release/github"
12+
]
13+
}
14+
}

0 commit comments

Comments
 (0)