limit allowed content types for avatar input
This commit is contained in:
		
							parent
							
								
									0e54722eef
								
							
						
					
					
						commit
						437c93463d
					
				
					 1 changed files with 3 additions and 2 deletions
				
			
		| 
						 | 
					@ -29,8 +29,9 @@ def convert_avatar(uri: str) -> bytes:
 | 
				
			||||||
    if not uri.startswith("data:image/"):
 | 
					    if not uri.startswith("data:image/"):
 | 
				
			||||||
        raise ValueError("Not a data URI")
 | 
					        raise ValueError("Not a data URI")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    content_type, encoded = uri.removeprefix("data:").split("base64,", 1)
 | 
					    content_type, encoded = uri.removeprefix("data:").split(";base64,", 1)
 | 
				
			||||||
    logger.info(f"{content_type=}")
 | 
					    if content_type not in ["image/png", "image/webp", "image/jpeg"]:
 | 
				
			||||||
 | 
					        raise ValueError("Invalid content type for image")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    img = pyvips.Image.thumbnail_buffer(
 | 
					    img = pyvips.Image.thumbnail_buffer(
 | 
				
			||||||
        base64.b64decode(encoded),
 | 
					        base64.b64decode(encoded),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue