Skip to content

fix: IPv6 per-IP limits, and the security audit with its attack test (#330) - #331

Merged
Lexirieru merged 4 commits into
mainfrom
fix/ipv6-limit-key
Nov 14, 2026
Merged

Lexirieru merged 4 commits into
mainfrom
fix/ipv6-limit-key

Conversation

@Lexirieru

Copy link
Copy Markdown
Contributor

Closes #330.

What changed

  1. fix(be): per-IP limits count an IPv6 address as its /64 (ipKey in apps/be/src/demo.ts). Found by attacking the hosted demo: after the sign-in challenge limit answered 429 over IPv6, the same machine still got 200 over IPv4. An IPv6 customer holds a whole /64 and could send each request from a new address, so the per-IP limits (guest sign-ups, guest runs, sign-in challenges) would not have limited them. A client with both IPv4 and IPv6 still gets two windows.
  2. docs/security/: the Threagile threat model, Sigma detection rules, Nuclei templates, an Osmedeus workflow and the results of the attack test.
  3. README and JUDGE.md: the security section says what the team audited and attacked before submission, with every attack tried and the API's answer. It still says no outside party has audited HelloNear.

Tests (local)

  • apps/be: bun run typecheck clean; bun run test 166 tests, 165 pass, 0 fail, 1 skipped; bun run load 0 errors, 0 runs missing events, approvals resumed exactly once.
  • New test per-IP limits count an IPv6 address as its /64 fails on the previous code and passes now.
  • sigma check docs/security/rules/: 0 errors. nuclei -validate: all templates valid. Threagile (Docker): the model parses and the report is written.
  • Not run: the Osmedeus workflow (Osmedeus is not installed here). The /64 rotation itself was not tried against the hosted demo; the test suite covers it.
  • No engine or web app changes.

After the merge

The deploy restarts the backend, which clears the in-memory limit windows (as every deploy does).

@Lin1er could you look at the ipKey change, since apps/be is yours? @AncungAulia @Nabil-Aufa FYI, nothing changes in the web app or the landing page.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q5ZrzK8une3S2YyhDG746e

Lexirieru and others added 4 commits November 14, 2026 23:48
Found by attacking the hosted demo from outside on 14 Nov: after the
sign-in challenge limit (60 per IP per hour) answered 429 over IPv6, the
same machine still got 200 over IPv4, and the same for guest sign-ups.
The limits were keyed on the full address. Two windows for a dual-stack
client is a factor of two, but an IPv6 customer holds a whole /64 and
can send every request from a new address, which would make the per-IP
limits (guest sign-ups, guest runs, sign-in challenges) no limit at all.
The /64 rotation itself was not tried; it follows from the key.

ipKey() now maps an IPv6 address to its /64 and ::ffff:a.b.c.d to the
IPv4 address. A client with both IPv4 and IPv6 still gets two windows.

Tests: new "per-IP limits count an IPv6 address as its /64" (fails on
the previous code, passes now). bun run typecheck clean; bun run test
166 tests, 165 pass, 0 fail, 1 skipped; bun run load 0 errors, 0 runs
missing events, approvals resumed exactly once.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q5ZrzK8une3S2YyhDG746e
…4 Nov attack test (#330)

The team's own security work on the hosted demo, kept in the repository
so anyone can repeat it: a Threagile model (15 technical assets, 16
threats mapped to STRIDE and OWASP Top 10:2025), six Sigma rules that
use the journal as it is today, three draft rules that need an access
log, five Nuclei templates that match on the wrong answer, an Osmedeus
v5 workflow, and the results of attacking api.hellonear.xyz from outside.

Validated: sigma check 0 errors; nuclei -validate passes; Threagile
(Docker) parses the model and writes its report (52 risks). Not
validated: the Osmedeus workflow (Osmedeus is not installed here); its
steps were run by hand.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q5ZrzK8une3S2YyhDG746e
…sted API (#330)

The security section now says plainly what was done before submission:
a review, a threat model and an attack test from outside, with a table
of every attack tried and what the hosted API answered, the one gap it
found (IPv6 addresses counted one by one, fixed in this branch) and what
is still missing (refusals are not logged). It stays clear that this is
the team's own audit and that no outside party has audited HelloNear.
JUDGE.md links to it from "Contracts and proofs".

Docs only; no tests affected.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q5ZrzK8une3S2YyhDG746e
…un (#330)

JUDGE.md now sums up the team's audit and the attack test in one table
and gives two curl commands that show a refusal without an account
(401 without a session, 403 from another origin; both checked against
the hosted API). It links to the README section and docs/security/.

Docs only; no tests affected.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q5ZrzK8une3S2YyhDG746e
@Lexirieru
Lexirieru merged commit b5197a0 into main Nov 14, 2026
1 check passed
@Lin1er

Lin1er commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

@Lexirieru looked at ipKey in b91f089 as asked. No blockers from the backend side.

  • Every caller of clientIp (guest sign-up, sign-in challenge, guest runs) now goes through ipKey. The Telegram pseudo-IP telegram:<id> is not IPv6, so it passes through unchanged.
  • Ran the function on edge cases outside the test suite: :: → 0:0:0:0::/64, a trailing :: (2001:db8:1:2:3:4:5::) → 2001:db8:1:2::/64, uppercase full form → lowercase, and a zone id (fe80::1%eth0) → fe80:0:0:0::/64. All correct.
  • One nit, not worth a change before judging: when the part after :: ends in a dotted IPv4 (1::2:3:4:1.2.3.4), the IPv4 counts as one group instead of two. The result is 1:0:0:0::/64 instead of 1:0:0:2::/64. Cloudflare's CF-Connecting-IP doesn't send global addresses in that form. Even if it did, the error would only put two networks under one key (stricter, not looser).

Not checked: the hosted deploy of b5197a0. That will follow in the usual "Live" comment.

@Lin1er

Lin1er commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Live on the hosted demo: main b5197a0 (automatic deploy after the merge).

  • Before: 6238384, and the box matched git at that revision. CI: passed: Mintlify Deployment,test.
  • GET /v1/health → {"ok":true,"engine":true,"revision":"b5197a0"}. No rollback.
  • Rollback target: 6238384 (/opt/hellonear/release-old).

@Lexirieru

Copy link
Copy Markdown
Contributor Author

Merged as b5197a0 with Axel's approval; the automatic deploy has run and #330 is closed.

Checked from outside after the deploy (17:1x UTC, 14 Nov):

  • GET /v1/health → {"ok":true,"engine":true,"revision":"b5197a0"}, the same on three checks 10 s apart. /v1/status: every service operational.
  • Sign-in challenge → 200 over IPv4 and over IPv6. Guest sign-in → 201, three templates listed.
  • Still refused as before: no session → 401, another origin → 403, /internal/v1/* → 404, a 300 KB body on /v1/auth/login → 413.
  • Not checked on the hosted demo: the /64 rule itself (it needs several addresses in one IPv6 network); the new test in apps/be/test/api.test.ts covers it. No flood was repeated, so no limit window was used up this time.

What is new on main:

  • per-IP limits count an IPv6 address as its /64 (ipKey in apps/be/src/demo.ts);
  • docs/security/: threat model (Threagile), Sigma rules, Nuclei templates, and the results of the attack test;
  • README "Security audit by the team" and a "Security check" section in JUDGE.md, with two commands a judge can run.

@Lin1er the ipKey change is in your folder and went in without your review because of the deadline; please read it when you can and say if anything should change. The attack test also ran against the box without a heads-up to you (details in #330). Left for after judging: an access log, so refused requests can be seen (finding 3 in #330).
@AncungAulia @Nabil-Aufa FYI: nothing changes in the web app or the landing page.
@Lexirieru (author).

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.

Attack test of the hosted demo (14 Nov): per-IP limits count each IPv6 address on its own

2 participants