Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qttestlib-security.qdoc
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5 \page qttest-security.html
6 \ingroup security-considerations
7 \title Qt Test Security Considerations
8 \brief How to keep tests from causing security problems.
9
10 The Qt Test framework manages the execution of tests and generates reports
11 on their results.
12 When using it, many of the considerations related to \l {Using
13 Qt's Developer Tools Securely} should be borne in mind.
14 As explained in the \l{Qt Shared Security Model} for Qt generally, those
15 using Qt Test need to take care about how they use Qt Test and the data it
16 will produce.
17
18 A good suite of tests will, in places, stress the code under test and thus
19 be in danger of failure, including by crashing or exercising undefined
20 behavior.
21 As the code under test evolves, from time to time it shall thereby catch
22 mistakes before they reach end-users.
23 Such failure may have surprising side-effects, including corrupting other
24 resources accessible to the test process, such as source code or build
25 artifacts.
26
27 Test failure may be accompanied by extra information describing the nature
28 of the failure.
29 Even when tests pass, they or the code they test may generate output, either
30 due to triggering warning or debug messages or in response to command-line
31 options.
32 The form of this data may render it difficult to report in some cases, or
33 may interfere with formatting of any report in which it is included, either
34 directly by Qt Test or by some other process consuming output produced by Qt
35 Test.
36
37 Users of Qt Test are advised to bear these points in mind:
38 \list
39 \li Test output may contain sensitive data, thereby making it accessible
40 to anyone in a position to read the output.
41 \li Particularly when the test code or code under test is not robustly
42 trusted, tests should be run by an unprivileged process wherever
43 possible and in a sandbox (such as a virtual machine) from which only
44 the report of test results shall be retained after testing.
45 \li Artifacts present on the test system should not be trusted to remain
46 as they were before tests were run.
47 \li Although Qt Test takes such care as it can to escape or otherwise
48 adapt data it embeds in its test output, so that the output adheres to
49 the format asked for, ensure tools that consume that output are robust
50 against the kinds of output your tests could produce.
51 \endlist
52
53 \section1 Build-time artifacts
54
55 Even before the test code is compiled, the build-time configuration of a
56 test may adapt the build environment, for example by adding to the build
57 configuration a requirement for software implicated in tests.
58
59 It is therefore important to understand what impacts such adaptations may
60 have on the build itself.
61 This may include changes to where build-time tools find source code to
62 incorporate or libraries to link against.
63 Where possible, adaptations needed for a test should not be applied to the
64 building of end-user-facing deliverables, but only to the building of each
65 test that needs them.
66
67 This is particularly important when changes to the build-time configuration
68 come from untrusted sources.
69 Such changes have been implicated in security compromises of software
70 packages.
71
72 \section1 General considerations
73
74 Automated testing is not a silver bullet.
75 Existing tests may fail to catch accidental errors or malicious changes and
76 the very fact of running tests may give such a change an opportunity to
77 cause harm.
78 New tests added with a change to the code under test may fail to
79 catch significant issues in the change, or issues in existing code
80 that come to light as a result of the change.
81
82 Following \l {Qt Test Best Practices} may help to make test behavior more
83 predictable and make it easier to avoid risks, including those to security.
84 As noted there, external dependencies may lead to problems, as described in
85 \l {Avoid external dependencies}.
86
87 As for \l{Using Qt's Developer Tools Securely}, you are responsible for the
88 integrity of the test environment, test code and code under test.
89 Qt Test is not designed to cope with malicious test code or code under test,
90 only to provide a convenient framework for writing tests that can give
91 informative reports when those tests fail.
92
93 \section2 Separate test and production builds
94
95 It is generally prudent to build deliverable software artifacts separately
96 from test artifacts and to save the deliverable artifacts where neither the
97 building of test artifacts nor the effects of running tests can interfere
98 with them.
99
100 Keeping these separate avoids potential problems that may arise due to some
101 malfunction in the building of the test, the test itself or the code under
102 test. All potentially have the ability to modify files on disk.
103 This can be a particular concern if any of these steps uses a network
104 connection to a remote server that might be compromised.
105
106 Test artifacts should not normally be needed in production systems.
107 Where there is a need to test on production systems, it is prudent to
108 package the tests separately from the code they test, to facilitate
109 uninstalling them once the tests have been run on the system to verify that
110 all is well.
111 This also makes it possible to install only the primary deliverables on
112 copies of the production system, once enough copies have been tested to
113 establish confidence that all systems shall work as intended.
114
115 \section2 Check output file names
116
117 As with any software which writes to files, Qt Test programs have options to
118 control where the output will be saved and in what format.
119
120 Where the output file names passed to such options are generated
121 automatically, for example by the build system or a quality management
122 system running the tests, care must be taken to ensure that the generated
123 names are as intended.
124 The system automatically generating such names should check that the names
125 it does generate meet expectations and do not place the output in places
126 where it may be misinterpreted by other systems, might overwrite or replace
127 data from other sources or is itself apt to be overwritten or replaced by
128 such data.
129*/