Watch out for setCookie and clearCookie opts, as clearCookie mutates opts instance
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 55/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- aws, javascript
調査の方向性
lib/response.js の221-224行目から始め、clearCookie が渡された options オブジェクトをどのように扱うかを調べてください。共有の cookie オプションを使用してログイン、ログアウト、ログインのシーケンスを再現し、その後、cookie のクリアが後続の setCookie 呼び出しに影響しないことを確認してください。実装を意図的に変更しない場合は、その動作を文書化してください。
索引モデルが issue の本文から書いたものです。
説明
Hi!
Lambda-api is a great package and has been really helpful in our one single backend lambda architecture 🚀
Today, I faced a really hard to debug issue and I though passing the information here if it helps anyone else. I was running our app with SAM CLI and everything worked like a charm, but when I deployed to AWS lambda, it worked in really weird way.
The problem was that I had somewhat the following structure:
const cookieOptions: CookieOptions = {
sameSite: 'Lax',
secure: true,
httpOnly: true,
}
// And pseudo authentication
api.post('/login', async (req,res) => {
// Do login stuff
res.setCookie('authcookie', sessionId, cookieOpts).json({ message: "Authenticated" })
})
api.post('/logout', async (req,res) => {
// Do logout stuff
res.clearCookie('authcookie', cookieOpts).json({ message: "Logged out" })
})
It worked locally like a charm. But when it was deployed to AWS Lambda, it worked like this:
- Login - OK you get a cookie
- Logout - OK cookie gets evicted
- Login - FAILS and no cookie is set
- After some time, it starts to work again, for once 😂
After some weird debugging I found out that the third call gets correct cookie, but with expiration set to -1, so the browser thinks that yes, unset the cookie.
Obvious reason for this is that response.clearCookie call mutates the given opts instance:
After the first response.clearCookie call my opts instance was mutated to contain expiration: -1 field and calls to response.setCookie after that naturally included the expiration.
The reason why it works after some time in AWS lambda is that runtime spins up a new sandbox and then it works again, for once 😄, because opts instance is not mutated and no one has logged out. Locally SAM CLI fires a whole new sandbox for each request and thus it worked locally with no issues.
You can easily work around this for example by wrapping opts in function:
const cookieOptions = (): CookieOptions => ({
sameSite: 'Lax',
secure: true,
httpOnly: true,
})
It surely took me some time to figure out what is going on 😄 I don't think this is mentioned in documentation. I think I can work out a PR for this if this is something that should be fixed - in code or with documentation.
- 主要言語
- JavaScript
- スター
- 1.5k
- フォーク
- 127
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
jeremydaly/lambda-api のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
jeremydaly/lambda-api#356 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
jeremydaly/lambda-api#270 ·
-
Logger Output再び着手できるかも @naorpeled が 907 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
jeremydaly/lambda-api#259 · コメント 1 件 · 担当者 1 名 ·
-
Is it possible to disable versioning?対応中かも @naorpeled が 102 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 52/100
jeremydaly/lambda-api#257 · コメント 5 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 38/100
jeremydaly/lambda-api#251 · コメント 1 件 ·
jeremydaly/lambda-api の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
woocommerce/woocommerce-google-analytics-integration#699 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
t0ggles
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
nolimits4web/swiper#8240 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
Inter-Actief/amelink#131 ·