firebase / firebase/extensions

storage-resize-images: unknown IMAGE_TYPE values produce broken output instead of being rejected, in both extension and kit

Open
#3,168 0 comments 0 reactions 0 assignees View on GitHub
type: bug
Dominant language
TypeScript
Stars
979
Forks
433
Avg merge
1d 22h
Merged PRs (30d)
127

Description

An `IMAGE_TYPE` value that is not a supported format is never validated. It reaches the resize path, produces an unconverted file with a bogus extension, and the run reports success.

With `IMAGE_TYPE` containing `bogus`, the output is written as `_.bogus` with `contentType: undefined`, which the bucket serves as `application/octet-stream`.

**Extension** (`storage-resize-images/functions/src/config.ts:39-41,85`):

```js
function paramToArray(param) {
return typeof param === "string" ? param.split(",") : undefined;
}
...
imageTypes: paramToArray(process.env.IMAGE_TYPE),
```

No allowlist, and `extension.yaml:229-252` declares `IMAGE_TYPE` as a `multiSelect` with no `validationRegex`, so nothing rejects an out-of-band value either.

Downstream, `functions/src/resize-image.ts:97-102` takes the content type from `supportedImageContentTypeMap[format]`, which is `undefined` for an unknown format, and appends `.${format}` to the filename. `functions/src/util.ts:196-247` falls through to `return buffer`, so the bytes are never converted.

**Kit** reproduces this exactly: `kits/storage-resize-images/src/export-config.ts:185` is `toArray(config.imageTypes) ?? [DEFAULT_IMAGE_TYPE]`, and `src/resize-image.ts:103-110` mirrors the extension.

In practice the picker limits selection to the declared options, so this needs an out-of-band value to trigger, for example a hand-edited `.env` or a value written by an older release. It is not reachable through the current UI in either codebase.

Worth deciding as one change across both, since fixing only the kit would make it create different output than the extension for the same configuration. Options are to reject at config resolve time, or to fall back to the default of keeping the original format.

Split out of #3124, which was closed as not a parity difference.

Contributor guide

Open the contributing guide

Research direction

Start with the extension files functions/src/config.ts, functions/src/resize-image.ts, functions/src/util.ts, and extension.yaml, then compare them with kits/storage-resize-images/src/export-config.ts and src/resize-image.ts. Reproduce an out-of-band bogus IMAGE_TYPE value and trace the configuration and resize paths. Done means both codebases consistently reject the value or apply the chosen default behavior without producing bogus output.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.