Skip to content

Attach auth headers for admin API calls#74

Merged
csecrestjr merged 1 commit into
mainfrom
codex/add-api-key-to-login-requests
Sep 1, 2025
Merged

Attach auth headers for admin API calls#74
csecrestjr merged 1 commit into
mainfrom
codex/add-api-key-to-login-requests

Conversation

@csecrestjr

Copy link
Copy Markdown
Collaborator

Summary

  • include configurable x-api-key in login
  • apply Authorization and API key headers to all Axios requests after login
  • expose API key via Next.js configuration

Testing

  • npm test
  • node -e "<mock login script>"

https://chatgpt.com/codex/tasks/task_e_68b4ea3882188321b49beca4744b2bb5

@csecrestjr
csecrestjr merged commit 3187e2d into main Sep 1, 2025
1 check passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Review: Here are some suggestions.

Reply with @codex fix comments to fix any unresolved comments.

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

Comment thread frontend/user_login.js
@@ -2,6 +2,7 @@ import { useState, useEffect } from "react";
import axios from "axios";

const BASE_URL = process.env.NEXT_PUBLIC_BACKEND_URL || "/api";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P0] Avoid exposing server API key to the browser

Declaring NEXT_PUBLIC_API_KEY and attaching it to Axios defaults means the admin API key is bundled into the client and sent on every request. In backend/middleware/authMiddleware.js the middleware grants access when either an x-api-key or a JWT is present, so anyone who loads the site can read the API key from the bundle and call /admin/* routes without logging in. This effectively bypasses authentication for the admin API. The key should stay server-side or the middleware must require a token even when a key is present.

Useful? React with 👍 / 👎.

@csecrestjr
csecrestjr deleted the codex/add-api-key-to-login-requests branch November 11, 2025 14:44
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 this pull request may close these issues.

1 participant