The Movie Database Support

Hello,

Since yesterday, my production application no longer works.

I use Vercel's serverless functions as a proxy for my front-end requests to the TMDB API. This function adds the Bearer token to http headers so that users don't see my API token.

// Vercel serverless function to proxy TMDB API requests

import { createProxyMiddleware } from 'http-proxy-middleware';
import type { Request, Response } from 'express';

const apiProxy = createProxyMiddleware({
  target: process.env['TMDB_API_URL'],
  changeOrigin: true,
  pathRewrite: {
    '^/api': '',
  },
  onProxyReq: proxyReq => {
    proxyReq.setHeader(
      'Authorization',
      `Bearer ${process.env['TMDB_API_TOKEN']}`
    );
  },
});

export default async function (req: Request<any>, res: Response<any>) {
  return apiProxy(req, res, () => ({}));
}

Until yesterday, everything had been running smoothly for over 8 months.

Error logs returned by the proxy function :

[Proxy Response] {
  statusCode: 403,
  path: '/configuration',
  headers: {
    'content-type': 'text/plain',
    'transfer-encoding': 'chunked',
    connection: 'close',
    date: 'Wed, 20 Nov 2024 08:34:23 GMT',
    server: 'openresty',
    'content-encoding': 'gzip',
    vary: 'Accept-Encoding,accept-encoding, Origin',
    'x-cache': 'Error from cloudfront',
    via: '1.1 b09c8a20b29053a362f3c1085a0f8990.cloudfront.net (CloudFront)',
    'x-amz-cf-pop': 'MRS52-P5',
    'alt-svc': 'h3=":443"; ma=86400',
    'x-amz-cf-id': 'wuVqwl7l58qHOjPJgJOfAgVIy7IMNAVgCnvhFOui9-kgrlbTQO3L9Q=='
  }
}

There is a possibility that my Vercel host has been blocked ?

When i try to use TMDB API with postman or with an other proxy there is no problem.

Thanks for helping.

4 replies (on page 1 of 1)

Jump to last post

Hi @dualshote,

I would assume this has to do with some security work we've been doing over the past week or so. We found an open issue where we were not enforcing the allowed host values, which could let 3rd parties masquerade as if they were the ones running api.themoviedb.org with a different domain.

The only way you'd be tripping over this change is if that is precisely what this proxy is inadvertently doing. Are you able to set the X-Forwarded-Host header by any chance? Set it to api.themoviedb.org, of course.

Thanks, I had the same issue and adding the header fixed it for me.

Hi @travisbell ,

The problem is now fixed by adding the header "X-Forwarded-Host" to "api.themoviedb.org".

https://www.movie-catalog.io/ is now online ;)

Thanks a lot for your help !

@travisbell in my app, we are still seeing some previous calls that were made earlier today without the X-Forward-Host still error when we execute with the new header being passed. Is there some caching on TMDB API that might explain that?

Can't find a movie or TV show? Login to create it.

Global

s focus the search bar
p open profile menu
esc close an open window
? open keyboard shortcut window

On media pages

b go back (or to parent when applicable)
e go to edit page

On TV season pages

(right arrow) go to next season
(left arrow) go to previous season

On TV episode pages

(right arrow) go to next episode
(left arrow) go to previous episode

On all image pages

a open add image window

On all edit pages

t open translation selector
ctrl+ s submit form

On discussion pages

n create new discussion
w toggle watching status
p toggle public/private
c toggle close/open
a open activity
r reply to discussion
l go to last reply
ctrl+ enter submit your message
(right arrow) next page
(left arrow) previous page

Settings

Want to rate or add this item to a list?

Login