OSIIX Library

Rechecking Defenses

Regression Tests for Defenses Examined in a Security Review

Type
Case study / technical record
Author
mars70s

1. Do not stop at “No issues found”

A security review may find that a particular input did not trigger unintended HTML interpretation, that a SQL-looking string was handled as data, or that internal information did not appear in a public response.

Those checks matter. But if their results are recorded only as review notes, a later change could quietly break the same assumption without anyone noticing.

During the Network Check Security Hardening work, four boundaries were examined: XSS, SQL Injection, Command Injection, and Error Information Leakage. This is not a conclusion that Network Check is secure as a whole. It is a small case study in turning the paths, inputs, and results that were examined into regression tests that can be checked again.

This article covers only some of the defenses examined in that security review. It is not a comprehensive account of Network Check's defenses.

The sequence can be summarized as follows:

Point-in-time review observation
        ↓
Reproducible assertion
        ↓
Regression guard for detecting future changes

These are not the same thing. A regression guard provides a way to recheck the condition written in the test. It does not prove that vulnerabilities are absent, establish application-wide coverage, or guarantee safety in the future.

2. Four boundaries examined

The four areas do not support conclusions of equal strength. The examined path, the defense observed, and the condition retained in a test need to be recorded separately.

AreaPath examinedDefense observedRegression assertionBoundary
XSSIndex header rendering, the security-header template, and the Multi Check rendererTemplate escaping, textContent, and createElementEscaped marker output and a source contract against unsafe sinksSelected paths only; not every route or browser execution
SQL InjectionSQLite path in usage_metrics.pyBound parameters using ? placeholdersSQL-looking values remain data in a temporary database, and the table remains queryableUsage metrics and a temporary database only
Command InjectionHTTP/2 curl subprocess pathInput validation, destination guard, list-form argv, and shell avoidanceRejection of metacharacter input and assertions about argv boundariesHTTP/2 path only
Error Information LeakageSelected check-function error results and the metrics page HTTP responseGeneralized messages changed during Security Hardening; selected markers, paths, and DSN-like values do not appearNegative assertions against selected results and responsesPARTIAL. Public reachability of destination_guard.py remains UNKNOWN

For XSS, SQL Injection, and Command Injection, the examined defenses already existed on the reviewed paths before the Security Hardening work; that work added regression tests to check them. Error Information Leakage is different: selected error messages were changed to generalized messages during the same work, and the changed behavior was then tested.

Here, “examined” refers to source and test code inspected for this article's evidence review. Tests and runtime behavior were not executed as part of that review.

3. XSS — Keep escaping and DOM sinks in the tests

Separate input, rendering, and expected result

The first regression test places a script-like marker in User-Agent and Accept-Language, which are displayed on the index page. In addition to asserting an HTTP 200 response, the test asserts that the raw marker is absent and its HTML-escaped representation is present.

The contract retained here is not that “all input is always safe.” For the header values covered by this test, the index template's response text contains no raw marker and does contain the escaped representation. Browser interpretation of that response was not tested.

A separate marker test covers the security-header template path. It places the marker in a result returned by a mocked check function and checks that a POST response from /security-headers contains no raw representation and does contain the escaped representation. The marker is in the mock return value, not in the URL input. Because the check function is mocked, this test does not exercise the entire path from remote header retrieval to rendering. It isolates the output-escaping boundary.

Inspecting the DOM sink

For dynamic Multi Check results, the renderer in static/multi_check.js creates elements with document.createElement and assigns values through textContent. The source regression test rejects innerHTML and insertAdjacentHTML in that script and requires textContent and document.createElement to be present.

This is not a test that launches a browser and operates the full page. It is a source contract. Likewise, the source observation that the reviewed template and static paths do not explicitly use |safe or Markup(...) is limited to the reviewed revision.

The bounded assertion retained for XSS is:

selected input
    → selected rendering path
    → escaped output / textContent
    → regression assertion

These test results cannot be generalized into a claim that the application has no XSS. Not every template, DOM sink, or browser behavior was examined.

4. SQL Injection — Treat SQL-looking strings as data

The SQL Injection review covers the SQLite path in network_check/usage_metrics.py. In record_usage_event, values such as the date, event type, target ID, count, and update time are passed as corresponding values for ? placeholders instead of being concatenated into SQL strings. Variables in the reviewed summary and dashboard queries are also passed as bound parameters.

The regression tests pass strings that look like parts of SQL statements as target_id or event_type values to a temporary SQLite database. They check that the strings remain values rather than being executed as SQL syntax. Another test checks that the tested metrics table remains queryable after a value with a malicious appearance is recorded.

The contract recorded here is:

reviewed usage-metrics value
    → bound parameter
    → stored as data in temporary SQLite
    → value retained / tested table remains queryable

These tests do not prove that SQL Injection is impossible. They do not cover a production database, other storage paths, future queries, or the entire path from a public request to a database. They preserve a condition for the reviewed parameter-binding path against selected values that look malicious.

5. Command Injection — Test the boundaries, not only the absence of a shell

The Command Injection review is limited to the curl subprocess path in the HTTP/2 check. Rather than calling one defense a “safe command,” this path is examined as several separate boundaries:

  1. Validate the input format.
  2. Check the destination with the destination guard.
  3. Pass values to the subprocess through list-form argv.
  4. Do not use shell=True on the reviewed path.
  5. Keep assertions for these conditions in regression tests.

The regression test uses input containing shell metacharacters that fails domain-format validation. The expected result is a generalized invalid-domain error, with neither the destination guard nor the subprocess called. This is a non-destructive test of Network Check's own input boundary, not an exploit procedure for a third-party target.

For a valid domain, the test inspects calls to a mocked subprocess.run: it asserts that the arguments are a list, that no shell keyword is used, and that the required --resolve value is in argv. Curl itself was not run, either in that test or during this article's evidence review. The source review also found that the searched application-scope subprocess path was limited to HTTP/2 subprocess.run; it found no Popen, os.system, or shell=True in that scope.

Input validation, destination checking, argv separation, and shell avoidance are not interchangeable. The destination guard is a connection-target boundary, not a substitute for shell parsing. List-form argv preserves the command-argument boundary, but it does not replace input or destination validation.

The tests therefore support only the statement that these boundaries can be rechecked with selected inputs on the reviewed HTTP/2 curl path. The result cannot be generalized to every Network Check subprocess, external script, or future command path.

6. Error Information Leakage — Check selected results for markers

This area differs from the other three. During Security Hardening, messages on selected error paths were changed to generalized messages, and regression tests were added for the changed behavior. This was not simply a case of preserving a pre-existing defense.

In the changed source, reviewed exception branches return function-specific generalized messages for cases such as security-header transport failures, HTTP/2 subprocess failures, TLS socket failures, selected resolver failures in DNS timing, MX, CAA, and PTR, and metrics dashboard failures. However, HTTP/2, TLS, and security headers have separate paths that pass a destination-guard error into the result unchanged. The final public exposure of those paths is unresolved, as described below.

The tests place strings such as internal markers, fake filesystem paths, private-address markers, and fake DSNs into mocked exceptions and related inputs. Tests for security headers, HTTP/2, DNS timing, MX, TLS, CAA, and PTR assert that markers do not appear in the error results returned by the check functions. These are check-function tests; they do not check the HTTP response that renders those results. The two metrics tests do inspect rendered HTTP responses: they use TestClient to request /usage-metrics and assert that marker and database-path strings do not appear in the response text. In addition, usage_metrics_status() returns only database existence status and does not pass the database filesystem path to the template.

This area is PARTIAL. The same marker test does not cover every public route or every error branch. For example, an MX marker path is tested, while SPF and DMARC have source-level generalized messages but no equivalent direct marker test in the reviewed file. Every rendered-route combination was not run in a browser.

The retained condition is limited to:

selected error behavior changed during Security Hardening
    → marker-bearing failure / input
    → marker absent from selected check-function result or metrics response
    → regression assertion

This is not coverage of the entire error surface.

Keep destination_guard.py UNKNOWN

The source review found that name resolution in destination_guard.py catches socket.gaierror and interpolates the exception value into an error string. The source shows a path where that value is returned from the guard, passed into HTTP/2, TLS, and security-header results, and rendered by the corresponding template as result.error.

The evidence reviewed for this article does not include a test that triggers a resolver error containing a marker and asserts what reaches the final public HTML or API response. No runtime or public request was made. The contents of an actual resolver error were not established either.

The classification in this article is therefore:

destination_guard.py resolver-error path
    classification: UNKNOWN
    description: potential but unproven public exposure

This does not classify the path as a confirmed vulnerability or leak, nor as safe or unreachable. It keeps an unverified path separate from the tested results.

7. What the areas have in common — From checking defenses to regression tests

The four areas involve different technical layers: HTML escaping, SQLite parameter binding, subprocess argv, and public error messages.

There is, however, a common pattern in how the work was recorded:

observed defense (or behavior changed during the same work for Error Information Leakage)
    → adversarial / negative input
    → observable expected result
    → regression assertion

For XSS, the expected result is escaped output or a text sink; for SQL Injection, data retention and continued table availability; for Command Injection, no subprocess call and an argv boundary; and for Error Information Leakage, absence of a marker.

This is not a claim that the pattern is a universal method for every security review. It is a case-study pattern for turning the reviewed paths in this Security Hardening work into tests that record which assumptions should be checked again.

8. What changes when a regression test is added

This section is mainly INFERENCE.

A review record is point-in-time information: “When this revision, input, and path were examined, this was observed.” When an observation is turned into a regression test, a future change that violates the written condition can be detected as a test failure when the test is rerun. The test cannot detect behavior changes that it does not express.

The review result can be brought closer to a condition like this:

Review-time observation:
    the selected marker did not appear in the result / response

Future detection condition:
    the test fails if the marker appears on the same selected path

This conversion does not strengthen the conclusion to “the system is safe.” It makes the selected condition reproducible and leaves an opportunity to detect a changed assumption. If the implementation changes, both the condition guarded by the test and the boundaries it does not cover need to be reviewed again.

The Network Check Security Hardening work-in-progress changelog records 70/70 PASS, and the final Security Hardening commit records 73/73 PASS (the changelog was later corrected to 73/73). Both are repository REPORTED history; neither is a result rerun for this article's evidence review. The current test suite was not run for this article.

9. What tests can and cannot establish

Adding regression tests can help preserve a review record. But the existence of tests and a passing result do not support broader conclusions by themselves.

  • The paths examined here are selected paths, not every route, template, DOM sink, database path, or subprocess path.
  • The inputs are selected payloads, not an inventory of every attack variant or input combination.
  • Paths that were not tested remain UNKNOWN; they have not been shown to be safe or unsafe.
  • Source structure and runtime behavior are not the same. No runtime or public request was made for this article's evidence review, and no browser execution was performed.
  • Some tests mock check functions or subprocesses to isolate a boundary. The actual retrieval outside those mocks and curl execution are not covered by those tests.
  • Dependency or framework changes may alter behavior even when the source-level intent is unchanged.
  • For Error Information Leakage, selected paths have generalized messages and marker assertions, but direct SPF/DMARC marker tests and other public routes remain unverified.
  • Whether a destination_guard.py resolver exception reaches a final public response remains UNKNOWN.
  • 70/70 and 73/73 are repository-reported history, not test results executed for this article.

Passing tests therefore do not prove that vulnerabilities are absent. They do not prove that Network Check is secure as a whole, that every exception is generalized, or that every route is covered.

10. Conclusion

The point of this article is not simply to record that “no issue was found.”

On the paths examined, header/template escaping, the Multi Check text sink, usage-metrics parameter binding, and the HTTP/2 argv boundary were assumptions that predated the work. For Error Information Leakage, selected error messages were changed during the same work, and the tests checked that markers did not appear afterward. Each case used unusual or malicious-looking inputs and retained an expected observable result as a regression assertion.

That made it possible to turn review-time observations into conditions that can be checked again after future changes. It is a concrete way to avoid leaving a defense at a one-time “no issue found” conclusion.

The conditions protect only what is written in the tests. Unexamined paths and the UNKNOWN around destination_guard.py remain visible boundaries for a future review.