cybersecurity · intermediate · ~15 min · safe pentest lab

Write a safe allowlist validator

Cap branching on user input to a known-good set.

Challenge

Implement int in_allowlist(const char *s, const char *const *allowed, size_t n) returning 1 if s is exactly equal to one of the strings in allowed, else 0. Use this as a building block for safe command dispatch where user input must select from a fixed menu.

Starter code

#include <stdio.h>
#include <string.h>
#include <stddef.h>

int in_allowlist(const char *s, const char *const *allowed, size_t n) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.