From 3ba951fa42ea7d60f86c7db383860777cc3ad79d Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Wed, 8 Nov 2023 22:51:39 +1100 Subject: [PATCH] feat: Remove scripts from render --- requirements.txt | 3 ++- sites/website.py | 13 +++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 81354d0..f1de7fd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,5 @@ email-validator py3dns passlib argon2-cffi -mysql-connector-python \ No newline at end of file +mysql-connector-python +beautifulsoup4 \ No newline at end of file diff --git a/sites/website.py b/sites/website.py index c9c9f25..0e98794 100644 --- a/sites/website.py +++ b/sites/website.py @@ -1,8 +1,17 @@ from flask import Flask, make_response, redirect, render_template_string, request, jsonify, render_template, send_from_directory - +from bs4 import BeautifulSoup def render(data): if data == "": return "No data found for this domain" - return render_template_string(data) \ No newline at end of file + try: + soup = BeautifulSoup(data, 'html.parser') + for script in soup.find_all('script'): + script.extract() + modified_data = str(soup) + return render_template_string(modified_data) + + + except Exception as e: + return "

Invalid HTML


" + str(e) \ No newline at end of file