refac
Co-Authored-By: Classic298 <27028174+Classic298@users.noreply.github.com>
This commit is contained in:
1 parent
a285a390c1
commit
eb53281c9a
2 files changed
+20
-5
No files matched your search
@@ -279,6 +279,11 @@ class UsersTable:
|
|||||||
oauth: dict | None = None,
|
oauth: dict | None = None,
|
||||||
db: AsyncSession | None = None,
|
db: AsyncSession | None = None,
|
||||||
) -> UserModel | None:
|
) -> UserModel | None:
|
||||||
|
try:
|
||||||
|
profile_image_url = validate_profile_image_url(profile_image_url)
|
||||||
|
except ValueError:
|
||||||
|
profile_image_url = '/user.png'
|
||||||
|
|
||||||
async with get_async_db_context(db) as session:
|
async with get_async_db_context(db) as session:
|
||||||
user = UserModel(
|
user = UserModel(
|
||||||
**{
|
**{
|
||||||
@@ -606,6 +611,11 @@ class UsersTable:
|
|||||||
profile_image_url: str,
|
profile_image_url: str,
|
||||||
db: AsyncSession | None = None,
|
db: AsyncSession | None = None,
|
||||||
) -> UserModel | None:
|
) -> UserModel | None:
|
||||||
|
try:
|
||||||
|
profile_image_url = validate_profile_image_url(profile_image_url)
|
||||||
|
except ValueError:
|
||||||
|
profile_image_url = '/user.png'
|
||||||
|
|
||||||
async with get_async_db_context(db) as session:
|
async with get_async_db_context(db) as session:
|
||||||
user = await session.get(User, id)
|
user = await session.get(User, id)
|
||||||
if user is None:
|
if user is None:
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import fnmatch
|
|||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import mimetypes
|
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
@@ -85,6 +84,7 @@ from open_webui.retrieval.web.utils import validate_url
|
|||||||
from open_webui.utils.auth import create_token, get_password_hash
|
from open_webui.utils.auth import create_token, get_password_hash
|
||||||
from open_webui.utils.groups import apply_default_group_assignment
|
from open_webui.utils.groups import apply_default_group_assignment
|
||||||
from open_webui.utils.misc import parse_duration
|
from open_webui.utils.misc import parse_duration
|
||||||
|
from open_webui.utils.validate import validate_profile_image_url
|
||||||
from starlette.responses import RedirectResponse
|
from starlette.responses import RedirectResponse
|
||||||
|
|
||||||
|
|
||||||
@@ -1648,12 +1648,17 @@ class OAuthManager:
|
|||||||
allow_redirects=AIOHTTP_CLIENT_ALLOW_REDIRECTS,
|
allow_redirects=AIOHTTP_CLIENT_ALLOW_REDIRECTS,
|
||||||
) as resp:
|
) as resp:
|
||||||
if resp.ok:
|
if resp.ok:
|
||||||
|
upstream_mime = (resp.headers.get('Content-Type', '') or '').split(';', 1)[0].strip().lower()
|
||||||
picture = await resp.read()
|
picture = await resp.read()
|
||||||
base64_encoded_picture = base64.b64encode(picture).decode('utf-8')
|
base64_encoded_picture = base64.b64encode(picture).decode('utf-8')
|
||||||
guessed_mime_type = mimetypes.guess_type(picture_url)[0]
|
try:
|
||||||
if guessed_mime_type is None:
|
return validate_profile_image_url(f'data:{upstream_mime};base64,{base64_encoded_picture}')
|
||||||
guessed_mime_type = 'image/jpeg'
|
except ValueError:
|
||||||
return f'data:{guessed_mime_type};base64,{base64_encoded_picture}'
|
log.warning(
|
||||||
|
f'Rejected OAuth profile picture from {picture_url}: '
|
||||||
|
f'MIME {upstream_mime!r} is not allowed'
|
||||||
|
)
|
||||||
|
return '/user.png'
|
||||||
else:
|
else:
|
||||||
log.warning(f'Failed to fetch profile picture from {picture_url}')
|
log.warning(f'Failed to fetch profile picture from {picture_url}')
|
||||||
return '/user.png'
|
return '/user.png'
|
||||||
|
|||||||
Reference in new issue
Block a user