Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[Question For Security Improvement] Hardcoded JWT secret `MY_SECRET` permits forged authentication cookies

オープン
#882 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
62/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
typescript

調査の方向性

Start with src/api.ts to trace how JWT_SECRET is used for signing and verification, then compare the related README_es.md section with .env.template. Done means the hardcoded secret is replaced by a required environment value, the template and teaching warning document that requirement, and a regression test covers rejection of tokens signed with MY_SECRET.

索引モデルが issue の本文から書いたものです。

説明

Hardcoded JWT secret MY_SECRET permits forged authentication cookies

Hello Lemoncode maintainers,

I understand that this repository contains an educational OAuth2 and JWT example. Could you please confirm whether MY_SECRET is intended only as a temporary teaching placeholder? Teaching examples should be especially careful with security defaults: otherwise, students may copy the pattern and reproduce the same vulnerability in real applications. Would you consider demonstrating a required high-entropy environment variable, adding it to .env.template, and explicitly warning that the placeholder must never be used in production?

The concise finding is below.

Summary

src/api.ts hardcodes the JWT signing key as MY_SECRET: api.ts#L20-L32. The code signs the authentication token with this value and places it in the authorization cookie: api.ts#L34-L47.

The same public value is used to verify the cookie token. The /api/user-profile endpoint trusts the verified id claim and returns the corresponding profile: api.ts#L50-L64.

Anyone who knows the repository can forge a valid JWT containing a known user ID and read that user’s profile without completing the Google OAuth flow. The current direct impact is unauthorized profile disclosure and authentication-cookie forgery. This report does not claim impact from routes that are not present in this example.

CVSS 3.1: 6.5 Medium (AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:N), for a reachable deployment using this example.

CWE: CWE-321 — Use of Hard-coded Cryptographic Key.

Evidence

The root cause is explicit:

const JWT_SECRET = 'MY_SECRET'; // TODO: Move to env variable

The README reproduces the same hardcoded key and still marks moving it to an environment variable as a TODO: README_es.md#L341-L356.

The teaching .env.template contains Google credentials but no JWT_SECRET field: .env.template#L1-L4.

The README describes the intended flow as storing the authenticated user ID in a JWT cookie, verifying it, and loading the profile by that ID: README_es.md#L172-L182.

Offline PoC

This generates a token locally only. It does not start the application or contact any online instance.

// Run in an isolated directory with jsonwebtoken installed.
const jwt = require('jsonwebtoken');

const token = jwt.sign(
  { id: 1 },
  'MY_SECRET',
  { algorithm: 'HS256' },
);

console.log(token);

For an authorized test instance, the generated token would be supplied as:

curl -H "Cookie: authorization=$TOKEN" \
  https://<authorized-test-instance>/api/user-profile

The request above is a test template only; it was not executed against the project or any third-party service.

Impact

An attacker who can reach an instance using this code can:

  • forge the authorization JWT cookie without completing Google OAuth;
  • choose a known user ID in the JWT payload;
  • retrieve the matching profile through /api/user-profile, including the profile fields returned by the repository.

If this authentication pattern is copied into additional protected routes, the same forged cookie can cross those authorization boundaries. That broader impact is not asserted for the current example because the finding is limited to the code shown above.

Remediation

  • Remove the hardcoded MY_SECRET value.
  • Load JWT_SECRET from the environment or a secret manager and fail startup when it is missing or empty.
  • Add JWT_SECRET to .env.template as a clearly marked high-entropy placeholder, for example JWT_SECRET=replace-with-a-high-entropy-secret.
  • Add a README warning that the example value must never be used outside local teaching.
  • Rotate the secret after deployment and invalidate tokens signed with MY_SECRET.
  • Add a regression test proving that a token signed with MY_SECRET is rejected by the production configuration.

Related works

Comparable public reports and fixes involving hardcoded or weak authentication secrets include:

This report is part of my ongoing security research. If anything is unclear or you would like to discuss the finding, please feel free to tag me or contact me at any time. I would be genuinely pleased to contribute, even in a small way, to improving the security of this project and its teaching material.

主要言語
TypeScript
スター
184
フォーク
99
平均マージ
1分
マージ済み PR(30日)
2

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Lemoncode/master-frontend-lemoncode のほかの issue

Lemoncode/master-frontend-lemoncode の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。