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

Background functions provide a clientContext and user locally, but not in production #4383

Closed
erquhart opened this issue Feb 26, 2022 · 1 comment · Fixed by #4395
Closed
Labels

Comments

@erquhart
Copy link
Contributor

erquhart commented Feb 26, 2022

Describe the bug

Background functions don't check for an authorization header token in production, so there's never a clientContext or any way to validate that an Identity authenticated user is sending the request. This isn't documented, but it's mentioned in a community answer: https://answers.netlify.com/t/clientcontext-user-missing-in-background-functions/46166/2

This can be hacked around pretty simply (I'm using a regular function to auth and then passing a secret to the background function), but it's a surprise when Netlify Dev does authenticate requests to background functions. So you put your authenticated background function live, it fails in production, and then you can't see why because background functions don't provide logs 🙈 (except sometimes they do??)

I can open a PR to simply remove clientContext for background functions here, which I’ve validated locally, but I didn't see an obvious way to test the inner workings of background functions in the current testing setup. Happy to open a PR with just the fix, or with tests too if anyone has thoughts on how to go about it.

To Reproduce

Steps to reproduce the behavior:

  1. Run a background function locally
  2. Send a request with a valid identity token in the authorization header
  3. Check for context.clientContext.user in the handler

Expected behavior

context.clientContext should be nullish, matching production

Thank you for making the cli amazing! While no pictures of animals were requested, I've provided complimentary hippos.

image

@erezrokah
Copy link
Contributor

Thanks @erquhart! We have an internal issue to track missing clientContext and this seems to be a AWS Lambda issue, aws/aws-sdk-js#1388 (comment).
We didn't have an issue for the CLI, so thank you for opening one!

We'd be happy to accept a PR to remove it as you suggested ❤️
Once the PR is up we can figure out the best way to test this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants