Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 2025-05-14 - Loose Loopback Validation
**Vulnerability:** `isLoopbackBindHost` incorrectly identified any hostname starting with "127." (e.g., `127.example.com`) as a loopback address. This could bypass the automatic API token generation for non-loopback binds (`ensureApiTokenForBindHost`), potentially exposing the API without authentication if a user binds to such a hostname that resolves to a public IP.
**Learning:** String prefix matching is insufficient for validating loopback addresses when hostnames are involved. Public DNS records can point to public IPs while having names that mimic private IP ranges.
**Prevention:** Always validate resolved IP addresses or use strict IP matching logic (like `net.isIP`) when enforcing network security policies based on address ranges. Do not rely on hostname patterns for security decisions.
10 changes: 10 additions & 0 deletions src/api/server.api-token-bind.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,14 @@ describe("ensureApiTokenForBindHost", () => {
false,
);
});

it("generates a token for non-loopback binds starting with 127.", () => {
delete process.env.MILADY_API_TOKEN;
const warnSpy = vi.spyOn(logger, "warn").mockImplementation(() => {});

ensureApiTokenForBindHost("127.example.com");

const generated = process.env.MILADY_API_TOKEN ?? "";
expect(generated).toMatch(/^[a-f0-9]{64}$/);
});
Comment on lines +49 to +57

Choose a reason for hiding this comment

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

Inconsistent logging assertion:
The test case for '127.example.com' (lines 49-57) verifies token generation but does not assert that the generated token is not logged, unlike the previous test for '0.0.0.0:2138'. This results in inconsistent coverage regarding the logging of sensitive information.

Recommendation:
Add an assertion similar to the previous test to ensure that the generated token is not present in any logger.warn messages:

const loggedMessages = warnSpy.mock.calls
  .map((call) => call[0])
  .map((value) => String(value));
expect(loggedMessages.some((message) => message.includes(generated))).toBe(false);

});
2 changes: 1 addition & 1 deletion src/api/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4317,7 +4317,7 @@ function isLoopbackBindHost(host: string): boolean {
) {
return true;
}
if (normalized.startsWith("127.")) return true;
if (net.isIP(normalized) === 4 && normalized.startsWith("127.")) return true;
return false;
}

Expand Down
Loading