fix: Verify link using regex
All checks were successful
Build Docker / Build Main Image (push) Successful in 20s
All checks were successful
Build Docker / Build Main Image (push) Successful in 20s
This commit is contained in:
parent
79b210c8a7
commit
2292b912d2
@ -16,6 +16,8 @@ services:
|
|||||||
DB_USER: main
|
DB_USER: main
|
||||||
DB_PASSWORD: your-db-password
|
DB_PASSWORD: your-db-password
|
||||||
DB_NAME: main
|
DB_NAME: main
|
||||||
|
DNS_SERVER: 10.1.1.2
|
||||||
|
DNS_SERVER_PORT: 5350
|
||||||
WORKERS: 2 # number of workers to run (should be 2 * number of cores)
|
WORKERS: 2 # number of workers to run (should be 2 * number of cores)
|
||||||
|
|
||||||
db:
|
db:
|
||||||
|
12
main.py
12
main.py
@ -7,6 +7,7 @@ import db
|
|||||||
import varo_auth
|
import varo_auth
|
||||||
import account
|
import account
|
||||||
import render
|
import render
|
||||||
|
import re
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
dotenv.load_dotenv()
|
dotenv.load_dotenv()
|
||||||
@ -97,18 +98,15 @@ def add_link():
|
|||||||
return resp
|
return resp
|
||||||
|
|
||||||
link=request.form['link']
|
link=request.form['link']
|
||||||
url=request.form['url']
|
url=request.form['url'].lower()
|
||||||
|
|
||||||
# Verify link is valid
|
# Verify link is valid
|
||||||
if not (url.startswith('http://') or url.startswith('https://')):
|
if not (url.startswith('http://') or url.startswith('https://')):
|
||||||
url = 'https://' + url
|
url = 'https://' + url
|
||||||
|
|
||||||
try:
|
regexmatch = re.match(r"^^https?://([a-z0-9]+(-[a-z0-9]+)*\.)*([a-z0-9]+(-[a-z0-9]+)*)(/([a-z0-9.])+(-([a-z0-9.])+)?)*$", domain)
|
||||||
r = requests.get(url, timeout=5)
|
if not regexmatch:
|
||||||
if r.status_code != 200:
|
return error('Invalid domain')
|
||||||
return error('Invalid URL')
|
|
||||||
except:
|
|
||||||
return error('Invalid URL')
|
|
||||||
|
|
||||||
if len(link) > 32:
|
if len(link) > 32:
|
||||||
return error('Link too long')
|
return error('Link too long')
|
||||||
|
Loading…
Reference in New Issue
Block a user