Skip to content

feat: add --public and --read-only flags for open access mode - #109

Merged
melvincarvalho merged 2 commits into
gh-pagesfrom
feature/public-flag
Jan 28, 2026
Merged

melvincarvalho merged 2 commits into
gh-pagesfrom
feature/public-flag

Conversation

@melvincarvalho

Copy link
Copy Markdown
Contributor

Summary

Implements #107 - adds --public and --read-only flags to allow JSS to be used as a simple file server similar to npx serve, but with write support.

Changes

New CLI Flags

  • --public - Skip WAC checks, allow unauthenticated read/write access
  • --read-only - Disable PUT/DELETE/PATCH methods

Environment Variables

  • JSS_PUBLIC=true
  • JSS_READ_ONLY=true

Config File

{
  "public": true,
  "readOnly": true
}

Usage

# Open read/write access (like a writable npx serve)
jss start --public

# Open read-only access (exactly like npx serve)
jss start --public --read-only

# Just read-only (still requires auth for reads)
jss start --read-only

Startup Warning

When public mode is enabled, a warning is displayed:

⚠️  WARNING: PUBLIC MODE ENABLED
   All files are accessible without authentication.
   Anyone can read, write, and delete files.
   Do not expose to the internet!

Files Changed

File Change
bin/jss.js Add CLI options, startup warning
src/config.js Add defaults and env var mapping
src/server.js Pass config to request object
src/auth/middleware.js Skip WAC in public mode
src/handlers/resource.js Block writes in read-only mode
src/handlers/container.js Block writes in read-only mode

Test Plan

  • --public flag shows in help
  • Server starts with --public flag
  • Server starts with --public --read-only flags
  • Warning message displayed on startup
  • Unauthenticated GET works in public mode
  • Unauthenticated PUT works in public mode
  • PUT returns 405 in read-only mode

Closes #107

Implements #107 - allows JSS to be used as a simple file server
similar to `npx serve` but with write support.

--public: Skip WAC checks, allow unauthenticated read/write access
--read-only: Disable PUT/DELETE/PATCH methods

Features:
- CLI flags: --public, --read-only
- Environment variables: JSS_PUBLIC, JSS_READ_ONLY
- Config file support: public, readOnly
- Startup warning when public mode enabled
- 405 Method Not Allowed for writes in read-only mode

Files changed:
- bin/jss.js: Add CLI options and startup warning
- src/config.js: Add defaults and env var mapping
- src/server.js: Pass config to request object
- src/auth/middleware.js: Skip WAC in public mode
- src/handlers/resource.js: Block writes in read-only mode
- src/handlers/container.js: Block writes in read-only mode

Copilot AI 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.

Pull request overview

Adds “open access” and “read-only” modes so JSS can act like a simple static/file server (optionally writable) via CLI flags, env vars, and config.

Changes:

  • Add --public and --read-only CLI flags plus a startup warning for public mode.
  • Extend config defaults/env var mapping for public and readOnly.
  • Thread these settings into request handling to skip WAC in public mode and reject write operations in read-only mode.

Reviewed changes

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

Show a summary per file
File Description
bin/jss.js Adds CLI flags, passes config into server options, prints public-mode warning/read-only status.
src/config.js Adds public/readOnly defaults and env var mapping.
src/server.js Decorates request with a config object containing public/readOnly.
src/auth/middleware.js Skips WAC checks in public mode and returns an always-authorized result.
src/handlers/resource.js Blocks PUT/DELETE/PATCH in read-only mode with 405 responses.
src/handlers/container.js Blocks POST and pod creation in read-only mode with 405 responses.

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

Comment thread src/auth/middleware.js
Comment on lines +31 to +34
// Public mode - skip all WAC checks, allow unauthenticated access
if (request.config?.public) {
return { authorized: true, webId: null, wacAllow: 'public="read write append"', authError: null };
}

Copilot AI Jan 28, 2026

Copy link

Choose a reason for hiding this comment

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

New behavior (public mode skipping WAC) and read-only write blocking is not covered by automated tests. This repo has a test/ suite; please add tests that verify unauthenticated GET/PUT in public mode and 405 behavior for write attempts in read-only mode (including verifying headers like Allow/WAC-Allow if applicable).

Copilot uses AI. Check for mistakes.
Comment thread src/auth/middleware.js Outdated

// Public mode - skip all WAC checks, allow unauthenticated access
if (request.config?.public) {
return { authorized: true, webId: null, wacAllow: 'public="read write append"', authError: null };

Copilot AI Jan 28, 2026

Copy link

Choose a reason for hiding this comment

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

Public mode always returns wacAllow: 'public="read write append"' even when readOnly is enabled, which makes the WAC-Allow header advertise write access that the handlers will later reject with 405. Please derive wacAllow from both public and readOnly (and consider including the user="..." part for consistency with other code paths).

Suggested change
return { authorized: true, webId: null, wacAllow: 'public="read write append"', authError: null };
const readOnly = !!request.config?.readOnly;
const publicModes = readOnly ? 'read' : 'read write append';
const userModes = readOnly ? 'read' : 'read write append';
const wacAllow = `user="${userModes}", public="${publicModes}"`;
return { authorized: true, webId: null, wacAllow, authError: null };

Copilot uses AI. Check for mistakes.
Comment thread src/handlers/resource.js
Comment on lines +514 to +517
// Read-only mode - block all writes
if (request.config?.readOnly) {
return reply.code(405).send({ error: 'Method Not Allowed', message: 'Server is in read-only mode' });
}

Copilot AI Jan 28, 2026

Copy link

Choose a reason for hiding this comment

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

Read-only mode blocks writes, but responses (notably OPTIONS) will still advertise Allow: GET, HEAD, PUT, DELETE, PATCH, OPTIONS... and Accept-Patch etc. This can confuse clients. Consider updating the LDP header generation / OPTIONS handling to omit write methods when request.config?.readOnly is true.

Copilot uses AI. Check for mistakes.
Comment thread src/handlers/container.js
Comment on lines 25 to +30
* Handle POST request to container (create new resource)
*/
export async function handlePost(request, reply) {
// Read-only mode - block all writes
if (request.config?.readOnly) {
return reply.code(405).send({ error: 'Method Not Allowed', message: 'Server is in read-only mode' });

Copilot AI Jan 28, 2026

Copy link

Choose a reason for hiding this comment

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

The same read-only check/response is duplicated across multiple handlers. To avoid missing write paths in the future (and to keep behavior consistent, e.g., headers/Allow), consider enforcing read-only via a centralized Fastify hook (e.g., onRequest/preHandler) that rejects unsafe methods when readOnly is enabled, and then keep per-handler checks only where exceptions are required.

Suggested change
* Handle POST request to container (create new resource)
*/
export async function handlePost(request, reply) {
// Read-only mode - block all writes
if (request.config?.readOnly) {
return reply.code(405).send({ error: 'Method Not Allowed', message: 'Server is in read-only mode' });
* Enforce read-only mode for unsafe methods.
* Returns a reply if the server is in read-only mode; otherwise returns null.
*/
function enforceReadOnly(request, reply) {
if (request.config?.readOnly) {
return reply
.code(405)
.send({ error: 'Method Not Allowed', message: 'Server is in read-only mode' });
}
return null;
}
/**
* Handle POST request to container (create new resource)
*/
export async function handlePost(request, reply) {
// Read-only mode - block all writes
const readOnlyResponse = enforceReadOnly(request, reply);
if (readOnlyResponse) {
return readOnlyResponse;

Copilot uses AI. Check for mistakes.
Copilot review feedback - the WAC-Allow header was advertising
write/append even when --read-only was enabled. Now correctly
returns only 'read' permissions when readOnly is true.
@melvincarvalho
melvincarvalho merged commit a0466f4 into gh-pages Jan 28, 2026
@melvincarvalho
melvincarvalho deleted the feature/public-flag branch January 28, 2026 10:50

Copilot AI 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.

Pull request overview

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


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

Comment thread src/config.js
// Public mode - skip WAC, allow unauthenticated access
public: false,

// Read-only mode - disable PUT/DELETE/PATCH

Copilot AI Jan 28, 2026

Copy link

Choose a reason for hiding this comment

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

The comment for readOnly says it disables PUT/DELETE/PATCH, but read-only mode in handlers also blocks POST (container/resource creation, pod creation). Update the config comment to match the actual behavior.

Suggested change
// Read-only mode - disable PUT/DELETE/PATCH
// Read-only mode - disable PUT/DELETE/PATCH/POST

Copilot uses AI. Check for mistakes.
Comment thread src/handlers/resource.js
*/
export async function handlePut(request, reply) {
// Read-only mode - block all writes
if (request.config?.readOnly) {

Copilot AI Jan 28, 2026

Copy link

Choose a reason for hiding this comment

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

When returning 405 for read-only mode, the response should indicate which methods remain allowed (e.g., via an Allow header). Also note that OPTIONS/normal responses will still advertise write methods via Allow/CORS headers; consider adjusting those headers in read-only mode so clients aren’t told PUT/POST/DELETE/PATCH are available.

Suggested change
if (request.config?.readOnly) {
if (request.config?.readOnly) {
reply.header('Allow', 'GET, HEAD, OPTIONS');

Copilot uses AI. Check for mistakes.
Comment thread src/handlers/container.js
*/
export async function handlePost(request, reply) {
// Read-only mode - block all writes
if (request.config?.readOnly) {

Copilot AI Jan 28, 2026

Copy link

Choose a reason for hiding this comment

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

When returning 405 for read-only mode, consider setting an Allow header that reflects the remaining permitted methods. This helps clients handle read-only mode correctly (and aligns with the Allow header your OPTIONS handler returns).

Suggested change
if (request.config?.readOnly) {
if (request.config?.readOnly) {
reply.header('Allow', 'GET, HEAD, OPTIONS');

Copilot uses AI. Check for mistakes.
Comment thread src/handlers/resource.js
Comment on lines +514 to +517
// Read-only mode - block all writes
if (request.config?.readOnly) {
return reply.code(405).send({ error: 'Method Not Allowed', message: 'Server is in read-only mode' });
}

Copilot AI Jan 28, 2026

Copy link

Choose a reason for hiding this comment

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

The read-only guard is duplicated across multiple handlers/files. Consider extracting a small helper (e.g., enforceReadOnly(request, reply)) to keep the behavior/message consistent and avoid missing a write endpoint in the future.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: --public flag to skip WAC and allow open access

2 participants