Skip to content

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

Open
@Skyfury2651

Description

@Skyfury2651

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-<hash>-an.a.run.app

Try access url https://myapp-<hash>-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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions