Skip to content

Commit

Permalink
fix: CWE-116 and CWE-79
Browse files Browse the repository at this point in the history
closes #15
  • Loading branch information
ialejandro committed Aug 15, 2024
1 parent 8844ac2 commit 5bb8891
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
11 changes: 4 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
FROM python:3.12.4-slim
ARG PYTHON_VERSION=3.12.4-slim

FROM python:${PYTHON_VERSION}

# LABELS
LABEL maintainer="Iván Alejandro Marugán <hello@ialejandro.rocks>" \
description="Bitbucket Bot for Google Chat" \
version="1.0.0"
description="Bitbucket Bot for Google Chat"

# APPLICATION
COPY app /app
COPY requirements.txt /requirements.txt

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

WORKDIR /app

# RUN APP
ENTRYPOINT ["gunicorn", "run:app"]
10 changes: 8 additions & 2 deletions app/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import html
import json
import os
import requests

from flask import Flask, request


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

if request.args['token']!= token:
exit(1)
return "Invalid token", 403

event = request.get_json()

if not event:
return "event empty"
return "event empty", 400

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

# Mitigate XSS
if isinstance(r, str):
r = html.escape(r)

return r


Expand Down
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "bitbucket-bot",
"version": "1.0.0",
"release": {
"branches": [
"main"
],
"repositoryUrl": "https://github.com/devops-ia/bitbucket-bot.git",
"plugins": [
"@semantic-release/release-notes-generator",
"@semantic-release/github"
]
}
}

0 comments on commit 5bb8891

Please sign in to comment.