Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Skyfury2651 opened this issue Nov 22, 2024 · 0 comments
Open

Comments

@Skyfury2651
Copy link

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.

@Skyfury2651 Skyfury2651 changed the title Firebase functions can't accept Windows-1252 URL encoding Firebase functions can't accept any encoding other than UTF-8 for URLs. Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants