Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Spot Misuse in a Week of Traffic

In this lesson, you read a simulated July week of traffic for misuse, in the two places your server records it, and decided what the server should do about each pattern you found.

Key Points

  • A simulated week. The traffic simulator’s script option adds a scripted user who sends a fresh hiker ID and a long page about hut 4 to translate with every question. Over 13 to 19 July, requests climbed from about two hundred a day to 677, and the bill climbed with them. The simulator knows who sent what. Your server doesn’t.
  • The first place: the traces and the server log. Neither holds a hiker ID, and a trace keeps a question’s fields, never its words. The trace writer keeps every error and every failed check, and one in ten of the rest.
  • Counting a sample. A small program, scripts/misuse-week.js, counts the week: a trace kept for an error or a failed check counts once, and a sampled one stands for ten. So the counts are estimates. The simulator’s 195 answers on the first day read as 168 model calls. The costs cover the answer model’s calls only, simulated, so moderation isn’t in them.
  • What the traces showed. The first three days looked ordinary: about 170 model calls, forty cents, and no long inputs. From the sixteenth, long inputs of over two thousand tokens jumped to hundreds a day, and 1,210 of the week’s 1,221 shared the same fields: hut 4, beds and dogs.
  • A lead, not proof. The same fields don’t prove one paste. Only the simulator knows they were copies of one translation request. The cost reached $4.15 a day, ten times the first days, and none of your guards reacted. The quota refused one hiker a day at most, off-topic questions stayed at a handful, and the log held seven moderation flags.
  • The second place: today’s quota counters. Only the quota’s Map holds tokens per hiker ID, and sweepQuota() deletes every earlier day, so you can read only today. tokensToday() returns today’s numbers without the IDs.
  • Reading the counters safely. Save the result of tokensToday() from inside the running server, because another process that imports quota.js gets an empty Map. On a real server, keep it to staff, as a local snapshot or an admin-only route, never for signed-in hikers.
  • What the counters showed. The counters hold quota tokens, where a cached token counts its price share, a twentieth at this answer model. On 19 July, 531 IDs asked. 452 sat between two and three and a half thousand quota tokens, about one long paste’s worth each, and together used 94 percent of the day’s quota tokens.
  • Tokens, not questions. Whether each ID asked once is a guess, and the next lesson adds a question count. The largest was one ID a little past the quota, like a group sharing a phone. The 452 stayed far under 8,000, so the quota never stopped them.
  • Pattern one: a scripted user. A free translator on hundreds of IDs. Its pastes name hut 4, so the scope check lets them through, as does the length check from Place Guardrails Around the Stream and the Cache. A line in the prompt can’t stop it: by the time the model reads it, you’ve paid for the paste.
  • Respond in your server. Tighten that length limit, and limit how fast new IDs arrive, above your busiest real minute so it doesn’t turn away real hikers. The next lesson measures where. This scripted user is a clear-cut one. A real script varies its text and timing, so it won’t stand out this clearly.
  • Pattern two: using the assistant for something else. The scope check refused off-topic questions, such as homework, before the answer call. Jailbreaks are harder to see. One answer was blocked for a go/no-go verdict, which an ordinary hiker can trip as well as a role-play.
  • A floor, not a count. The simulator sent five role-plays, and the ones whose answers passed left no mark, so a blocked count is a floor, not a count of attempts. Review each blocked one in the wardens’ desk queue, and keep counting.
  • The gap. You can’t look back, because the sweep deleted the counters for the sixteenth to the eighteenth. You’d need a daily record, written before the sweep, with no IDs.
  • The rule: look for misuse where your server records it: patterns without IDs in the traces, scaled up for the sample, and patterns per hiker in today’s quota counters, before the sweep. Then decide what your server does about each.

Final Code

In quota.js, below sweepQuota():

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 In Hand Over to a Person, you sent hikers to the wardens’ desk. Soon the assistant goes on the trust’s public site, where some people will misuse it. Here’s a simulated July week.

00:12 The simulator’s script option adds a scripted user: a fresh hiker ID and a long page about hut 4 to translate, every time.

00:22 Watch the week run. Requests climb from about two hundred a day to six hundred and seventy-seven, and the bill with them. The simulator knows who sent what.

00:32 Your server doesn’t.

00:36 Your server records the week in two places. First, the traces and the log. Neither holds a hiker ID, and a trace keeps a question’s fields, never its words.

00:47 The trace writer keeps every error and failed check, but only one in ten of the rest.

00:53 So a small program, misuse-week, counts them. A trace with a failure counts once. A sampled trace stands for ten.

01:03 The first three days look ordinary: about a hundred and seventy model calls, forty cents, and no long inputs. They’re estimates. The simulator’s hundred and ninety-five reads as a hundred and sixty-eight.

01:16 From the sixteenth, long inputs of over two thousand tokens jump to hundreds a day. Twelve hundred and ten of the week’s twelve hundred and twenty-one share the same fields: hut 4, beds and dogs.

01:29 That’s a lead, not proof of one paste. The cost reaches four dollars fifteen a day, ten times the first days.

01:39 None of your guards reacted. The quota refused one hiker a day at most, off-topic questions stayed at a handful, and the log holds seven moderation flags.

01:51 The traces can’t say if that’s one person or hundreds. Only the quota’s Map holds tokens per hiker ID. And sweepQuota() deletes every earlier day, so you can read only today, the nineteenth.

02:05 In quota.js, add tokensToday(), which returns today’s numbers without the IDs. From inside the running server, save its result as quota-today.json, and run a second program on it.

02:21 Five hundred and thirty-one IDs asked today. Four hundred and fifty-two sit between two and three and a half thousand quota tokens, where a cached token counts for less.

02:31 That’s about one long paste’s worth each. Together they use ninety-four percent of today’s tokens.

02:39 The largest is one ID a little past the quota, like a group sharing a phone. The four hundred and fifty-two stay far under eight thousand, so the quota never stops them.

02:52 The week shows two patterns. The first is a scripted user, a free translator on hundreds of IDs. Its pastes name hut 4, so the scope check lets them through, as does your length check from Place Guardrails.

03:05 A prompt line can’t stop it. By the time the model reads it, you’ve paid for the paste. So respond in your server: tighten that length limit, and limit how fast new IDs arrive.

03:18 Second, people using it for something else. The scope check refused the homework before the answer call. Jailbreaks are harder to see. One answer was blocked for a go/no-go verdict, which an ordinary hiker can trip as easily as a role-play.

03:34 Attempts whose answers passed leave no mark, so that count is a floor. Review each blocked one in the wardens’ desk queue, and keep counting. And you can’t look back.

03:46 The sixteenth to the eighteenth had counters too, and the sweep deleted them. You’d need a daily record, written before the sweep, with no IDs.

03:57 So look for misuse where your server records it: patterns without IDs in the traces, scaled up for the sample, and patterns per hiker in today’s quota counters, before the sweep.

04:08 Then decide what your server does about each. Next, in Stop Scripts That Get Past the Quota, you’ll add the limits this scripted user got past.

Become a Member to join the conversation.