cybersecurity · beginner · ~12 min · safe pentest lab
Structural validation of a dotted, character-restricted token.
int jwt_is_wellformed(const char *tok);
Return 1 if tok is structurally a JWT — exactly three non-empty segments
separated by ., where every segment character is base64url
(A-Z a-z 0-9 - _). Otherwise 0 (including NULL).
(Decoding the header to reject alg:"none" is a separate, deeper check — this
one is structure only.)
Before you ever verify a JWT's signature you must confirm its shape: exactly three base64url segments. Malformed tokens should be rejected early.
int jwt_is_wellformed(const char *tok) {
/* TODO */
(void)tok;
return 0;
}
Allowing empty segments. Accepting standard base64 chars (+/=). Not requiring exactly two dots.
Trailing dot (empty last segment). Four parts. Empty string.
O(n).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.