arcjet-js: Astro: Redirects cause adapter to fail
It seems that redirects defined in astro.config.mjs cause our adapter to fail. This is due to the context.isPrerendered flag being set to false yet context.clientAddress throws when accessed. This generally makes sense because a redirect doesn’t produce a static page itself.
Astro doesn’t seem to have anything like isRedirect on the context but you can discover redirects during the build process. I experimented with using codegen to make an isDynamic function that consumed the discovered redirects but I’m not sure I’m happy with users needed to import the utility explictly.
Instead, we could use this generated logic to warn and produce an Allow decision on static pages. Alternatively, we could produce an Error decision like we do when IP isn’t defined. I’m not sure which is better.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 21 (21 by maintainers)
Commits related to this issue
- chore(astro): add temporary warning message for fully static sites (#4278) Closes #3094 In my testing, we only run into #3094 when there are no dynamic routes. In that case `protect` is never bei... — committed to arcjet/arcjet-js by qw-in a year ago
- chore(astro): Increase minimum peerDependency (#4432) This increases the minimum peerDep recommendation for Astro in our SDK adapter to v5.9.3 This version included @qw-in's fix for static redirec... — committed to arcjet/arcjet-js by blaine-arcjet a year ago
This was mostly solved by @qw-in fixing the bug upstream in Astro, but we’ve also added a warning.
I’ll be bumping the peerDep minimum to help guide users to the fixed version.
Feel free to submit it, but I’m pretty staunchly against us supplying APIs for bugs in a framework. I think our time would be better spent fixing the bug in Astro.
I already documented this in the root issue:
Found it, working on repro now
@qw-in Thanks for trying to reproduce! I wonder if they inadvertently fixed the problem with some other change. I grepped their changelog and saw this mention of clientAddress. Maybe it solved the issue—it may be useful to bisect the Astro versions to know which is the known-good-version.