Improve security and social sharing for video thumbnails

Implements SHA256 hashing for Bunny.net tokens and proxies thumbnail requests for social sharing compatibility in `server/bunny.ts` and `server/routes.ts`.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 50814a1e-92e4-4968-856f-7bc7eedf5e8f
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/8cc42625-c1f5-4e43-99bd-77f2c4dedee2/50814a1e-92e4-4968-856f-7bc7eedf5e8f/q65IwWw
This commit is contained in:
sebastjanartic
2025-08-04 19:20:19 +00:00
parent e9c136a92a
commit fd78ef1545
2 changed files with 24 additions and 23 deletions
+12 -3
View File
@@ -62,10 +62,14 @@ export class BunnyService {
}
const expireTimestamp = Math.floor(Date.now() / 1000) + (expiryHours * 3600);
const tokenContent = `${this.securityKey}${path}${expireTimestamp}`;
const hash = crypto.createHash('md5').update(tokenContent).digest();
// Bunny.net uses SHA256 for token generation according to docs
// hashableBase = securityKey + signaturePath + expires + userIp + parameterData
const hashableBase = `${this.securityKey}${path}${expireTimestamp}`;
const hash = crypto.createHash('sha256').update(hashableBase).digest();
const token = Buffer.from(hash).toString('base64')
.replace(/\n/g, '')
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=/g, '');
@@ -84,7 +88,12 @@ export class BunnyService {
const thumbnailPath = `/${bunnyVideo.guid}/${bunnyVideo.thumbnailFileName || 'thumbnail.jpg'}`;
const videoUrl = this.generateSignedUrl(videoPath);
const thumbnailUrl = this.generateSignedUrl(thumbnailPath);
// For thumbnails, try direct signed URL for now to debug the issue
const directThumbnailUrl = this.generateSignedUrl(thumbnailPath);
// Use proxy endpoint for social sharing compatibility
const thumbnailUrl = `/thumbnail/${bunnyVideo.guid}`;
return {
id: bunnyVideo.guid,