Skip to content

Commit

Permalink
fix: resolve CodeQL error
Browse files Browse the repository at this point in the history
  • Loading branch information
gauthier-th committed Oct 16, 2024
1 parent 27d7371 commit 7ff242d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions server/routes/avatarproxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ router.get('/*', async (req, res) => {
let imagePath = '';
try {
const jellyfinAvatar = req.url.match(
/(.*?)(\/Users\/\w+\/Images\/Primary\/\?tag=\w+&quality=90)$/
)?.[2];
/.*?(\/Users\/\w+\/Images\/Primary\/?\?tag=\w+&quality=90)$/
)?.[1];

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on
a user-provided value
may run slow on strings with many repetitions of 'a'.
if (!jellyfinAvatar) {
throw new Error('Provided URL is not a Jellyfin avatar.');
}
Expand Down
16 changes: 7 additions & 9 deletions src/components/Common/CachedImage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,17 @@ const CachedImage = ({ src, type, ...props }: CachedImageProps) => {

let imageUrl: string;

if (src.startsWith('/')) {
// that's not an image to proxy
imageUrl = src;
} else if (type === 'tmdb') {
if (type === 'tmdb') {
// tmdb stuff
imageUrl = currentSettings.cacheImages
? src.replace('https://image.tmdb.org', '/imageproxy')
: src;
imageUrl =
currentSettings.cacheImages && !src.startsWith('/')
? src.replace('https://image.tmdb.org', '/imageproxy')
: src;
} else if (type === 'avatar') {
// jellyfin avatar (in any)
const jellyfinAvatar = src.match(
/^(.*?)(\/Users\/\w+\/Images\/Primary\/\?tag=\w+&quality=90)$/
)?.[2];
/^.*?(\/Users\/\w+\/Images\/Primary\/?\?tag=\w+&quality=90)$/
)?.[1];
imageUrl = jellyfinAvatar ? `/avatarproxy` + jellyfinAvatar : src;
} else {
return null;
Expand Down

0 comments on commit 7ff242d

Please sign in to comment.