Skip to main content

2026-11-30 · 8 min read

Three developer tools: cron's OR rule, JWT without verification, and a config checker that only trusts what the docs say

DevOpsSecurity

Translated from the Chinese original: read it in Chinese

The previous batch was three small tools for travelling in Japan. This batch is three for people who write code and self-host:

  • Cron expression explainer: paste */5 * * * *, get a plain-language reading and the next 5 run times
  • Base64 / URL / JWT: encode and decode, and open up a JWT to look inside
  • Tunnel config checker: paste a Cloudflare Tunnel config.yml and check the ingress rules

(All three tool pages are in Chinese.) None of the code is long. What took thought was one question: when the tool says "wrong" or "fine", on what authority? I will take the three tools in turn.

1. Cron: if day and weekday are both set, it is "or", not "and"

What does 0 0 1 * 1 mean? Many people read it as "on the 1st of the month, if that day is a Monday". In Vixie cron's convention, when both the day-of-month and the day-of-week fields are not *, the job runs when either one matches. So this line means "on the 1st of every month, and also every Monday".

The rule is a few lines of code, but if it is wrong the user has no way to see that:

if (s.domStar && s.dowStar) return true;
if (s.domStar) return inDow;
if (s.dowStar) return inDom;
return inDom || inDow; // both restricted: either one matches

The unit test pins it with an example you can compute by hand: starting at noon on 2026-11-30, the next three runs of 0 0 1 * 1 are 12/1, 12/7 and 12/14 (12/1 is the 1st of the month, and happens to be a Tuesday; 12/7 and 12/14 are Mondays). When both fields are restricted, the tool also adds a line saying "runs if either matches", so nobody misreads it.

The next run time is not found minute by minute but day by day: check whether the day's month, date and weekday match, and only then expand "hours × minutes" into that day's times. That way 0 0 30 2 * (February 30th) cannot hang: scanning 8 years finds nothing and returns an empty array, and the page explains it will never happen; 0 0 29 2 * does find 2028-02-29, which is also in the tests.

Time zones: only ones without daylight saving

The options are Taipei, Tokyo and UTC. All of them are fixed offsets, so converting wall-clock time to UTC is adding or subtracting a constant, with no need to handle the hour that repeats or vanishes at a daylight saving switch. The cost is that the tool cannot answer "my server is in New York"; the page notes that which time zone a schedule actually runs in depends on the machine's settings.

2. JWT: decodable does not mean genuine

The first two parts of a JWT are just Base64 (URL-safe) encoded JSON, readable by anyone. So "decoding" has no security meaning on its own; what matters is verifying the signature, and that needs a key.

This tool only "opens it up to look": header and payload, with the three time fields exp, iat and nbf converted to Taipei time and judged as expired, not yet valid, or not yet expired. Because it is easy to misunderstand, the status line on the page is always followed by the sentence "contents decoded only, signature not verified, which does not mean this token is genuine".

There is one small decision in the Base64 part: everything is treated as UTF-8 text. Using atob directly turns Chinese into garbled characters, so encoding goes through TextEncoder to bytes first, and decoding uses TextDecoder("utf-8", { fatal: true }). The benefit of fatal: true is that when the decoded bytes are not valid UTF-8 (for example if someone pastes the Base64 of an image), it throws, and the tool can say "decoded, but not valid UTF-8 text" instead of showing a pile of question marks. Tests pin the two-character Chinese "hello" ↔ 5L2g5aW9, and that /w== (the single byte 0xFF, not valid UTF-8) returns an error.

3. Tunnel config checker: only what the docs say is an error

This was the one needing the most care. The easiest mistake for a config checker is treating your own guesses as rules: the user pastes a config that actually works, the tool shows a red "error", and the user starts doubting themselves or stops trusting the tool.

So before writing it I read Cloudflare's official "Configuration file" page (marked updated 2026-11-10), and separated what it explicitly says from what it does not spell out:

Stated in the docs → "error" or "warning"Not stated → only an "explanation" or "heads-up"
A config with ingress rules must end with a catch-all (no hostname and no path)Whether rules are "first match wins" (it only appears in the description of the ingress rule test command)
Wildcards are supported only at the start, *.example.com, not in the middleWhat exactly happens when the catch-all is missing
warp-routing is no longer supported from cloudflared 2023.9.0 and produces a config warningWhether service must include a protocol (some official examples write http://, some omit it)

So: a missing catch-all, a wildcard in the middle, and http_status: not followed by a 3-digit number are "errors"; a wildcard rule placed before specific domains is only a "heads-up", and the text tells the user to run the official cloudflared tunnel ingress rule <URL> to see which rule actually matches; a service without a protocol is an "explanation".

The tool also does not pretend to be a full YAML parser: it works line by line and only understands the common forms of tunnel, credentials-file and the ingress list. The page says so, and recommends running the official cloudflared tunnel ingress validate on the machine as the most accurate check.

A regex that almost let "no protocol" slip through

To decide whether service has a protocol, my first version was:

!/^[a-z][a-z0-9+.-]*:/i.test(r.service)

One test case had service: localhost:3000 and expected the "no protocol" explanation, which did not appear. The reason is silly: localhost: itself matches "starts with letters, followed by a colon", so it was taken as a protocol. I changed it to require :// (and also allow unix:):

!/^([a-z][a-z0-9+.-]*:\/\/|unix(\+tls)?:)/i.test(r.service)

Without that test case, the tool would have stayed silent after launch on the most common way of leaving the protocol out (localhost:3000).

Tests where I was the one who was wrong

While writing these three tools, tests failed 4 times, and in 3 of them the wrong thing was my expected answer, not the code:

  1. The "now" in the time zone test was exactly the next run time. I set "now" to 09:00 Tokyo and expected the next run at 09:00 the same day. But cron counts from "the next minute", the current minute does not count, so the answer is the next day. The tool was right and my test was wrong. I changed "now" to 08:59.
  2. The wording of the plain-language description. I expected the longer Chinese phrasing for "Monday to Friday 09:00", and the output used the shorter form that reads more naturally. I changed the test.
  3. "Every day at 08:00, 12:00, 18:00". I expected no "every day", the output had it, and it reads better.
  4. A missing space between month and day in the Chinese output (the "1" of the month ran straight into the day number). This one was the code's fault, and the test was right.

That is roughly 3 to 1. When a test fails, first ask "which side is wrong"; do not reflexively change the code to fit the test, and do not reflexively change the test to fit the code.

What was verified and what was not

  • All 577 unit tests in the project pass; type check and eslint are clean.
  • 37 E2E tests pass, including the new ones (cron URL parameters and bad input, Base64 with Chinese round trip, the JWT example showing expired with Taipei time, the Tunnel example and the missing catch-all, related-post links), the a11y scan, and the sitemap.
  • I measured the three pages at phone width (375px) and there is no horizontal scrolling.
  • Not verified: the Tunnel checker was not compared against real config files and the output of cloudflared tunnel ingress validate; the cron tool only covers the standard 5 fields, not 6 fields with seconds or Quartz's L, W, #; the JWT tool does no signature verification at all.

Summary

  • For a tool that judges right and wrong, first separate what the docs say from what they do not say. The former can be called an error; the latter can only be a heads-up.
  • Cron's day and weekday are OR; scanning for the next run by "day" is more stable than by "minute", and it handles February 30th naturally.
  • A decodable JWT is not necessarily genuine, and the interface should keep reminding people of that.
  • Decode Base64 with fatal: true to tell "text" from "binary".
  • When a test fails, first decide whether the code or the expectation is wrong.

Type to search projects and posts too