π¨ The ultimate agentic social media scheduling tool π€
TypeScript nextjsopen-sourceopen-source-social-media-scheduling-toolosspostiz-cloudpostiz-hostedredisscheduling-toolsocial-media-scheduling-tooltypescript
fix: harden streamed uploads after a full audit against origin/main
Nevo David4013c1af0744
diff --git a/libraries/nestjs-libraries/src/integrations/social.abstract.ts b/libraries/nestjs-libraries/src/integrations/social.abstract.tsindex 5a48ff51b..6db987825 100644--- a/libraries/nestjs-libraries/src/integrations/social.abstract.ts+++ b/libraries/nestjs-libraries/src/integrations/social.abstract.ts@@ -180,9 +180,12 @@ export abstract class SocialAbstract {protected async mediaSize(path: string, identifier = ''): Promise<number> {if (path.indexOf('http') === 0) {// the media path is user-influenced, keep the SSRF-safe dispatcher that- // this.fetch applies to every other outbound request+ // this.fetch applies to every other outbound request. identity encoding+ // so content-length matches the bytes a later GET actually streams+ // (fetch transparently decompresses encoded bodies).const head = await fetch(path, {method: 'HEAD',+ headers: { 'accept-encoding': 'identity' },dispatcher: getSsrfSafeDispatcher(),} as any);const length = Number(head.headers.get('content-length'));@@ -213,7 +216,10 @@ export abstract class SocialAbstract {): Promise<Buffer> {if (path.indexOf('http') === 0) {const response = await fetch(path, {- headers: { Range: `bytes=${start}-${end}` },+ headers: {+ Range: `bytes=${start}-${end}`,+ 'accept-encoding': 'identity',+ },dispatcher: getSsrfSafeDispatcher(),} as any);// Anything but 206 means the server ignored the Range header: buffering@@ -250,7 +256,10 @@ export abstract class SocialAbstract {return createReadStream(path);}+ // identity encoding so the streamed byte count matches the size mediaSize+ // reported - a decompressed body would overflow any declared length.const response = await fetch(path, {+ headers: { 'accept-encoding': 'identity' },dispatcher: getSsrfSafeDispatcher(),} as any);@@ -287,7 +296,10 @@ export abstract class SocialAbstract {const status = err.response.status || 500;const data = err.response.data;- const json = typeof data === 'string' ? data : safeStringify(data || {});+ // '|| {}' / "|| '{}'" match this.fetch, which never hands handleErrors+ // an empty string.+ const json =+ (typeof data === 'string' ? data : safeStringify(data || {})) || '{}';const handleError = this.handleErrors(json, status);if (diff --git a/libraries/nestjs-libraries/src/integrations/social/bluesky.provider.ts b/libraries/nestjs-libraries/src/integrations/social/bluesky.provider.tsindex edba9f530..e5b02faed 100644--- a/libraries/nestjs-libraries/src/integrations/social/bluesky.provider.ts+++ b/libraries/nestjs-libraries/src/integrations/social/bluesky.provider.ts@@ -79,6 +79,8 @@ async function uploadVideo(// and the bytes are streamed straight from the source into the upload.const headResponse = await fetch(videoPath, {method: 'HEAD',+ // identity encoding so content-length matches the bytes the GET streams+ headers: { 'accept-encoding': 'identity' },// @ts-ignore - undici-only option; blocks SSRF to internal IPsdispatcher: getSsrfSafeDispatcher(),});@@ -93,6 +95,7 @@ async function uploadVideo(}const videoResponse = await fetch(videoPath, {+ headers: { 'accept-encoding': 'identity' },// @ts-ignore - undici-only option; blocks SSRF to internal IPsdispatcher: getSsrfSafeDispatcher(),});diff --git a/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.ts b/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.tsindex 0727ba7c4..7816f70c6 100644--- a/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.ts+++ b/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.ts@@ -646,7 +646,9 @@ export class LinkedinProvider extends SocialAbstract implements SocialProvider {// GIFs pass through untouched (sharp would break animation). Videos never// reach this function - they are streamed by uploadPicture instead.if (isGif) {- return readOrFetch(mediaUrl);+ // Buffer.from keeps the return type a real Buffer regardless of what+ // readOrFetch yields - uploadPicture branches on Buffer.isBuffer.+ return Buffer.from(await readOrFetch(mediaUrl));}const mime = lookup(mediaUrl);diff --git a/libraries/nestjs-libraries/src/integrations/social/mastodon.provider.ts b/libraries/nestjs-libraries/src/integrations/social/mastodon.provider.tsindex a3c12bff6..e1f0c108e 100644--- a/libraries/nestjs-libraries/src/integrations/social/mastodon.provider.ts+++ b/libraries/nestjs-libraries/src/integrations/social/mastodon.provider.ts@@ -146,6 +146,8 @@ export class MastodonProvider extends SocialAbstract implements SocialProvider {// a consumed stream can't be replayed.const media = await this.runStreamedUpload<{ id: string }>(async () => {const fileResponse = await fetch(fileUrl, {+ // identity encoding so content-length matches the streamed bytes+ headers: { 'accept-encoding': 'identity' },// @ts-ignore - undici-only option; blocks SSRF to internal IPsdispatcher: getSsrfSafeDispatcher(),});diff --git a/libraries/nestjs-libraries/src/integrations/social/skool.provider.ts b/libraries/nestjs-libraries/src/integrations/social/skool.provider.tsindex 2abc60a79..a0df90f76 100644--- a/libraries/nestjs-libraries/src/integrations/social/skool.provider.ts+++ b/libraries/nestjs-libraries/src/integrations/social/skool.provider.ts@@ -211,6 +211,8 @@ export class SkoolProvider extends SocialAbstract implements SocialProvider {// bytes so the file is never buffered in memory.const headResponse = await fetch(item.path, {method: 'HEAD',+ // identity encoding so content-length matches the bytes the GET streams+ headers: { 'accept-encoding': 'identity' },// @ts-ignore - undici-only option; blocks SSRF to internal IPsdispatcher: getSsrfSafeDispatcher(),});@@ -250,6 +252,7 @@ export class SkoolProvider extends SocialAbstract implements SocialProvider {).json();const fileResponse = await fetch(item.path, {+ headers: { 'accept-encoding': 'identity' },// @ts-ignore - undici-only option; blocks SSRF to internal IPsdispatcher: getSsrfSafeDispatcher(),});diff --git a/libraries/nestjs-libraries/src/integrations/social/tumblr.provider.ts b/libraries/nestjs-libraries/src/integrations/social/tumblr.provider.tsindex 593a4814d..c19533146 100644--- a/libraries/nestjs-libraries/src/integrations/social/tumblr.provider.ts+++ b/libraries/nestjs-libraries/src/integrations/social/tumblr.provider.ts@@ -5,6 +5,7 @@ import {SocialProvider,} from '@gitroom/nestjs-libraries/integrations/social/social.integrations.interface';import {+ BadBody,SocialAbstract,ValidityMedia,} from '@gitroom/nestjs-libraries/integrations/social.abstract';@@ -544,6 +545,17 @@ export class TumblrProvider extends SocialAbstract implements SocialProvider {});+ // axios parses JSON silently: a non-JSON 200 (proxy/WAF page) comes+ // back as a raw string, which would publish the post with an empty id.+ if (!response || typeof response !== 'object' || !response.response) {+ throw new BadBody(+ this.identifier,+ String(response || '{}'),+ '{}',+ 'Tumblr did not return a valid post response'+ );+ }+return response as TumblrCreatePostResponse;}, this.identifier);}diff --git a/libraries/nestjs-libraries/src/integrations/social/whop.provider.ts b/libraries/nestjs-libraries/src/integrations/social/whop.provider.tsindex e453694f2..86295a57c 100644--- a/libraries/nestjs-libraries/src/integrations/social/whop.provider.ts+++ b/libraries/nestjs-libraries/src/integrations/social/whop.provider.ts@@ -234,6 +234,8 @@ export class WhopProvider extends SocialAbstract implements SocialProvider {// through the whole ~9 minute status poll).const headResponse = await fetch(item.path, {method: 'HEAD',+ // identity encoding so content-length matches the bytes the GET streams+ headers: { 'accept-encoding': 'identity' },// @ts-ignore - undici-only option; blocks SSRF to internal IPsdispatcher: getSsrfSafeDispatcher(),});@@ -270,6 +272,7 @@ export class WhopProvider extends SocialAbstract implements SocialProvider {if (createFileResponse.upload_url) {const fileResponse = await fetch(item.path, {+ headers: { 'accept-encoding': 'identity' },// @ts-ignore - undici-only option; blocks SSRF to internal IPsdispatcher: getSsrfSafeDispatcher(),});