Skip to content

feat(server): check optional bearer access token#382

Merged
wjmelements merged 5 commits intomasterfrom
server-authtoken
Apr 1, 2026
Merged

feat(server): check optional bearer access token#382
wjmelements merged 5 commits intomasterfrom
server-authtoken

Conversation

@wjmelements
Copy link
Copy Markdown
Contributor

Reviewer @SgtPooki
This authentication provides minimal security for servers that need it.
If access token is supplied, reject requests not matching access token

Changes

  • --access_token

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@wjmelements wjmelements requested a review from SgtPooki March 25, 2026 05:41
@FilOzzy FilOzzy added team/filecoin-pin "Filecoin Pin" project is a stakeholder for this work. team/fs-wg FOC working group is a stakeholder for this work, and thus wants to track it on their project board. labels Mar 25, 2026
@FilOzzy FilOzzy added this to FOC Mar 25, 2026
@github-project-automation github-project-automation bot moved this to 📌 Triage in FOC Mar 25, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an optional server-side bearer access token check to provide minimal request authentication for the Filecoin pinning API server when configured.

Changes:

  • Add Config.accessToken and load it from ACCESS_TOKEN.
  • Add --access-token CLI flag that sets ACCESS_TOKEN.
  • Enforce configured token matching in the server preHandler hook.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/filecoin-pinning-server.ts Rejects requests whose bearer token doesn’t match config.accessToken when configured.
src/core/synapse/index.ts Extends shared Config type with accessToken.
src/config.ts Loads accessToken from process.env.ACCESS_TOKEN.
src/commands/server.ts Adds CLI option to set ACCESS_TOKEN via --access-token.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +129 to +132
if (config.accessToken && token !== config.accessToken) {
await reply.code(401).send({ error: 'Invalid access token' })
return
}
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

The new config.accessToken enforcement branch isn’t covered by tests right now. Please add coverage that verifies requests are rejected with 401 when a configured access token does not match, and accepted when it matches (and consider a test for missing/invalid header behavior when the access token is configured).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is some server test coverage on another branch (#376) that I would prefer to extend, instead of adding another test here. Fewer merge conflicts that way.

Comment on lines 51 to 54
// Synapse SDK configuration
privateKey: process.env.PRIVATE_KEY, // Required: Ethereum-compatible private key
accessToken: process.env.ACCESS_TOKEN,
rpcUrl, // Determined from RPC_URL, NETWORK, or default to calibration
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

createConfig() now reads ACCESS_TOKEN, but the surrounding configuration docs only mention PRIVATE_KEY, RPC_URL, and NETWORK. Consider updating the comment/docs to include ACCESS_TOKEN (and what format is expected: the raw token value, not the Bearer prefix).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this is obvious, but I've also done a lot of stuff with bearer tokens.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You should move accessToken up to the "Application-specific" section cause this section is documented as the Synapse fields

@BigLep BigLep moved this from 📌 Triage to 🔎 Awaiting review in FOC Mar 27, 2026
Comment on lines +117 to +121
// If no access token is configured, allow all requests
if (!config.accessToken) {
request.user = DEFAULT_USER_INFO
return
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@rvagg might have better insight, but this seems okay to me. may be easy to miss for consumers though

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this is good because you will often be running this pinning server on the same machine as the client (e.g. pinmfs). If we don't want this behavior, then we need to make access-token mandatory.

Copy link
Copy Markdown
Collaborator

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

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

im good with this but you might want @rvagg feedback

@github-project-automation github-project-automation bot moved this from 🔎 Awaiting review to ✔️ Approved by reviewer in FOC Mar 27, 2026
@rjan90 rjan90 added this to the M4.2: mainnet GA milestone Mar 30, 2026
Copy link
Copy Markdown
Member

@rvagg rvagg left a comment

Choose a reason for hiding this comment

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

I don't even remember writing this code! So long ago. Maybe I was stubbing future functionality.

Seems fine to me, just move that field in config.ts.

@BigLep
Copy link
Copy Markdown
Member

BigLep commented Apr 1, 2026

@wjmelements : will let you make the update and merge - thanks.

@wjmelements wjmelements merged commit 67ee879 into master Apr 1, 2026
12 checks passed
@wjmelements wjmelements deleted the server-authtoken branch April 1, 2026 00:42
@github-project-automation github-project-automation bot moved this from ✔️ Approved by reviewer to 🎉 Done in FOC Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team/filecoin-pin "Filecoin Pin" project is a stakeholder for this work. team/fs-wg FOC working group is a stakeholder for this work, and thus wants to track it on their project board.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants