Skip to content

fix the npx thing#1181

Merged
MathurAditya724 merged 3 commits intomainfrom
adi/fix/npx
Dec 4, 2025
Merged

fix the npx thing#1181
MathurAditya724 merged 3 commits intomainfrom
adi/fix/npx

Conversation

@MathurAditya724
Copy link
Copy Markdown
Member

closes #1180

@vercel
Copy link
Copy Markdown

vercel bot commented Dec 4, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
spotlightjs Ready Ready Preview Comment Dec 4, 2025 0:43am

Comment on lines 79 to +84
// manually decompress body to use it below without another decompression
const body = decompressBody(Buffer.from(await ctx.req.arrayBuffer()), ctx.req.header("Content-Encoding"));
const body = decompressBody(
Buffer.from(await ctx.req.arrayBuffer()),
ctx.req.header("Content-Encoding") as ContentEncoding,
);

This comment was marked as outdated.

const body = decompressBody(
Buffer.from(await ctx.req.arrayBuffer()),
ctx.req.header("Content-Encoding") as ContentEncoding,
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Unsafe type cast may crash on unsupported encodings

The cast ctx.req.header("Content-Encoding") as ContentEncoding is unsafe. The Content-Encoding header can contain values like "identity" or other unsupported encodings that aren't in the decompressors map ("gzip" | "deflate" | "br"). When an unsupported encoding is passed, decompressors[contentEncoding] returns undefined, and calling undefined(body) throws a TypeError. The cast hides this from TypeScript but the runtime crash remains.

Fix in Cursor Fix in Web

Copy link
Copy Markdown
Member

@BYK BYK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol, thanks!

Comment thread .changeset/fuzzy-years-admire.md Outdated

// Custom plugin to add shebang to the CLI entry point
// This runs after all other transformations to ensure the shebang is the first line
const shebangPlugin = (): Plugin => ({
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol, so this was the missing bit?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, as initially we were compiling using tsc, so this was added already

@BYK BYK deployed to Preview December 4, 2025 12:42 — with GitHub Actions Active
enforce: "post",
generateBundle(_options, bundle) {
for (const [fileName, chunk] of Object.entries(bundle)) {
if (fileName === "run.js" && chunk.type === "chunk") {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a concern, we also have cli/run.js would that be a problem?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The npx command uses the ./src/run.ts as described in the package.json. And this name comes from the vite config - vite.node.config.ts.

So this shouldn't be a problem

Comment on lines +81 to +84
const body = decompressBody(
Buffer.from(await ctx.req.arrayBuffer()),
ctx.req.header("Content-Encoding") as ContentEncoding,
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Unsafe type cast of Content-Encoding header allows unsupported values to cause a TypeError and server crash.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The ctx.req.header("Content-Encoding") value, which can be string | undefined, is unsafely cast as ContentEncoding without runtime validation. If a client sends an unsupported Content-Encoding header (e.g., zstd), decompressors[contentEncoding] evaluates to undefined. Attempting to call this undefined value as a function results in a TypeError, causing the server to crash.

💡 Suggested Fix

Implement runtime validation for the Content-Encoding header value. If the value is not one of the supported gzip, deflate, or br encodings, return an appropriate error response instead of proceeding with decompression.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: packages/spotlight/src/server/routes/stream/index.ts#L81-L84

Potential issue: The `ctx.req.header("Content-Encoding")` value, which can be `string |
undefined`, is unsafely cast `as ContentEncoding` without runtime validation. If a
client sends an unsupported `Content-Encoding` header (e.g., `zstd`),
`decompressors[contentEncoding]` evaluates to `undefined`. Attempting to call this
`undefined` value as a function results in a `TypeError`, causing the server to crash.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 5492537

@MathurAditya724 MathurAditya724 merged commit 6faf91f into main Dec 4, 2025
22 checks passed
@MathurAditya724 MathurAditya724 deleted the adi/fix/npx branch December 4, 2025 12:50
MathurAditya724 pushed a commit that referenced this pull request Dec 4, 2025
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and publish to npm
yourself or [setup this action to publish
automatically](https://github.com/changesets/action#with-publishing). If
you're not ready to do a release yet, that's fine, whenever you add more
changesets to main, this PR will be updated.


# Releases
## @spotlightjs/spotlight@4.7.1

### Patch Changes

- Report `github-ci` environment to Sentry when running in GitHub
Actions CI ([#1178](#1178))

- Fix `npx @spotlightjs/spotlight` fail
([#1181](#1181))

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

npx @spotlightjs/spotlight is broken

2 participants