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

Usage of aws-jwt-verify fails with missing "https.request" and "crypto.createPublicKey" #519

Open
ottokruse opened this issue Aug 2, 2024 · 2 comments

Comments

@ottokruse
Copy link

ottokruse commented Aug 2, 2024

I had a stab at using LLRT for running an API Gateway Lambda authorizer with the aws-jwt-verify JS lib (I'm one of the maintainers of that) in LLRT and I'd like to report my findings.

Missing https module

aws-jwt-verify uses the Node.js "https" module which leads to an error when importing aws-jwt-verify:

ReferenceError: Error resolving module 'https' from '/var/task/index.mjs'

Interestingly you can plug other HTTP helpers into aws-jwt-verify, such as fetch, which at first I thought would be a solution--but it's not because the static import { request } from "https", even though unused, remains in the aws-jwt-verify code and will trip up usage in LLRT.

Was able to overcome this with some esbuild magic, injecting a stub https module with a non implemented request function, so that the import doesn't fail (and then plugging in fetch instead).

I'm not sure what the best way forward is, but the thought did occur to me that it might be helpful for LLRT to include stubs like that for all Node.js modules, and raise NotImplementedError when calling not implemented functions? At least the static imports work then, and you'd only run into the NotImplementedError if you or the libraries you use actually use those Node.js functions.

Especially for libraries I can see that be of use, since they often do many static imports, in code paths that your code might not actually be using.

Note: aws-jwt-verify uses Node.js https module because it supports older Node versions (from 16 onwards) that do not have fetch onboard yet.

Missing 'createPublicKey' in module 'crypto'

After solving the https import error I ran into: SyntaxError: Could not find export 'createPublicKey' in module 'crypto'

Cannot stub that out so for now my LLRT journey with aws-jwt-verify ends.


Thanks for the LLRT effort!

@Sytten
Copy link
Contributor

Sytten commented Aug 2, 2024

Crypto module is pretty bare bone right now, it doesn't support much and indeed not the createPublicKey.

@richarddavison
Copy link
Contributor

Hi @ottokruse thanks for your comments. That's a valid concern. Crypto will reach web-crypto / subtle compliance in the future. In regards to http and https modules that's a different beast as they are heavily dependent on stream support. We have a stream stub (pulled from Node.js) but it's not ported to Rust as the API is huge. We also have a native stream implementation that doesn't have feature parity and is used for child processes. The plan right now is to add this "minimal" stream API for http and https modules in version 1.0 but right now users would have to use build tooling (such as esbuild) to replace them with empty implementations. I know this is not ideal and maybe we should provide a mechanism like you suggested to provide runtime errors at the callsite.

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

No branches or pull requests

3 participants