-
Notifications
You must be signed in to change notification settings - Fork 157
Description
Motivation
The PuterHomepageService is responsible for serving the Puter homepage and configuring social media metadata, including the social media preview image. When an invalid social media image URL is provided (either malformed or with an unsupported file extension), the service needs to validate it and fall back to a default image.
Currently, the validation logic has a critical bug that causes a runtime error when an invalid URL is encountered. This prevents the homepage from loading properly and degrades the user experience.
Current Behavior
The social media image validation logic attempts to reassign a const variable when the URL fails validation checks. In JavaScript, const variables cannot be reassigned after their initial declaration.
Reproduction Steps
- Navigate to
src/backend/src/services/PuterHomepageService.js - Locate the social media image validation logic (around line 219)
- Configure the service with an invalid social media image URL
- Example: a URL without a valid image extension like
.txt, or a malformed URL
- Example: a URL without a valid image extension like
- Start the service and attempt to load the homepage
- Observe: The service throws a runtime error attempting to reassign the
const social_media_imagevariable
Expected Behavior
The service should validate the social media image URL without causing runtime errors.
When an invalid URL is provided, the validation logic should detect the issue and use the default social media image instead.
The validation should:
- Ensure the URL is properly formed
- Check that it ends with a valid image extension (
.png,.jpg,.jpeg,.gif, or.webp)
Acceptance Criteria
- The validation logic does not attempt to reassign
constvariables - Invalid URLs (malformed or non-absolute) are properly detected and handled
- URLs without valid image extensions are properly detected and handled
- When validation fails, the service falls back to the default social media image (
${asset_dir}/images/screenshot.png) - The homepage loads successfully regardless of whether the configured social media image URL is valid or invalid
Steps to Test
-
Set a valid social media image URL
- Example:
https://example.com/image.png
- Example:
-
Open the homepage in a browser
- Verify the page loads successfully (no errors).
- Check page source →
og:imageandtwitter:imagemeta tags show the configured image URL.
-
Set an invalid image URL (bad extension)
- Example:
https://example.com/file.txt
- Example:
-
Reload the homepage
- Verify the page still loads (no runtime error).
- Confirm
og:imageandtwitter:imagenow show the default fallback image (${asset_dir}/images/screenshot.png).
-
Set a malformed or non-absolute URL
- Example:
not-a-valid-urlor/relative/path.png
- Example:
-
Reload the homepage
- Confirm it still loads successfully.
- Verify fallback image is used again.
- Check console/logs → no “Assignment to constant variable” or similar runtime errors.
Submission
Download https://cap.so/ to record your screen (use Studio mode). Export as an mp4, and drag and drop into an issue comment below.
Guide to submitting pull requests: https://hackmd.io/@timothy1ee/Hky8kV3hlx