firebase / firebase/firebase-functions

Firebase functions can't accept any encoding other than UTF-8 for URLs.

Open
#1,646 5 comments 0 reactions 1 assignee Claimed by @IzaakGough View on GitHub
api: http bug reproduced
Dominant language
TypeScript
Stars
1.1k
Forks
232
Avg merge
20h 46m
Merged PRs (30d)
15

Description

### Related issues

### [REQUIRED] Version info

**node:**
v20.11.0

**firebase-functions:** v4.9.0

**firebase-tools:** 13.25.0

**firebase-admin:** ^12.0.0

### [REQUIRED] Test case

```
import basicAuth from 'basic-auth-connect';
const cookieParser = require('cookie-parser');

const server = express();
server.use(cookieParser(process.env.COOKIE_SECRET));
server.disable('x-powered-by');
server.all(
'/*',
basicAuth(
(user: string, passwd: string) =>
user === 'username' && passwd === 'passwd ',
),
);

// Middleware to catch and validate URL encoding
server.use((req, res, next) => {
try {
decodeURIComponent(req.url); // Try to decode the URL
next(); // Continue if decoding is successful
} catch (err) {
// If decoding fails, return a 400 Bad Request with a custom error message
res.status(400).send({ error: 'Invalid URL encoding' });
}
});

server.use('*', express.static(__dirname + '/static/'));

export const newapp = functions.https.onRequest(
{},
server,
);
```
### [REQUIRED] Steps to reproduce

Link to https cloud functions gen2 ( Cloud run ) :
`https://myapp--an.a.run.app`

Try access url `https://myapp--an.a.run.app/%C3` with param or query that contain encoded characters like Windows-1252 , ISO-8859-1( Example: %C3 ) will return internal server error.

### [REQUIRED] Expected behavior

Function can access url contain other than UTF-8 encoded characters without throw internal server error. ( Or just throw 400 bad request )

### [REQUIRED] Actual behavior

Error: No default engine was specified and no extension was provided.

### Were you able to successfully deploy your functions?

Function is successfully deployed, only occur an error when meet special characters in url.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.