Work on this exercise locally

This web app is a reference guide — you can read instructions, browse starter code, and view tests here. To actually complete the exercise, you need to work in your local development environment.

1Clone the repo: git clone https://github.com/weihaoqu/program-analysis-bootcamp-student
2Edit the starter file in your editor (VS Code, Vim, etc.) — replace failwith "TODO" with your implementation.
3Run the tests: dune runtest modules/module5-security-analysis/exercises/security-config

Security Config

4. Exercise 2: Security Config (17 tests)

Goal: Define a security configuration with sources, sinks, sanitizers, and lookup/mutation helpers.

Time: ~20 minutes

File to edit: exercises/security-config/starter/config.ml

Dependencies: shared_ast

The configuration types

These record types are pre-defined:

type source = { source_name: string; source_description: string }
type sink = { sink_name: string; sink_param_index: int;
              sink_vuln_type: string; sink_description: string }
type sanitizer = { sanitizer_name: string; sanitizer_cleans: string list;
                   sanitizer_description: string }
type security_config = { sources: source list; sinks: sink list;
                         sanitizers: sanitizer list }

What to implement (in order)

#FunctionHint
1empty_configAll three lists empty
2default_web_configBuild the full config with 5 sources, 5 sinks, 5 sanitizers (see table below)
3is_source config nameList.exists checking source_name
4find_sink config nameList.find_opt checking sink_name
5find_sanitizer config nameList.find_opt checking sanitizer_name
6sink_checks_param sink idxCompare sink.sink_param_index to idx
7sanitizer_cleans san vuln_typeList.mem vuln_type san.sanitizer_cleans
8add_source config sourcePrepend to config.sources
9add_sink config sinkPrepend to config.sinks
10add_sanitizer config sanPrepend to config.sanitizers

The default web config

SourcesSinks (param 0)Sanitizers
get_paramexec_query (sql-injection)escape_sql (cleans: sql-injection)
read_cookiesend_response (xss)html_encode (cleans: xss)
read_inputexec_cmd (command-injection)shell_escape (cleans: command-injection)
read_fileopen_file (path-traversal)validate_path (cleans: path-traversal)
get_headerredirect (open-redirect)validate_url (cleans: open-redirect)

All sinks check parameter index 0. Each sanitizer cleans exactly one vulnerability type.

Run tests

dune runtest modules/module5-security-analysis/exercises/security-config/

Starter output (before any implementation):

Fatal error: exception Failure("TODO: return empty config")

The test framework calls empty_config first. Once you implement it and default_web_config, the lookup tests will start running. Build up the config step by step.

Hint: The tests check exact string values for sink_vuln_type (e.g. "sql-injection", not "SQLi"). Match the strings in the table above exactly.