test(iast): resolve Filelock import targets through public API #22052
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.50) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 608 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.384
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #22052"
general
weight: 0.35
avara1986
Description
Related to https://datadoghq.atlassian.net/browse/APPSEC-71951
The package-compatibility tests import
filelock._apifor both Filelock 3.14 and the latest release. Filelock 4.3 movedBaseFileLocktofilelock._core._lockand removed_api, so both the plain and the IAST-patched import checks fail on the latest version before exercising the package.The test runner now accepts a
module:attributeselector and validates the submodule that defines the attribute, and Filelock is selected through its publicBaseFileLockexport:pkgutil.resolve_name. Plain module names import exactly as before.__module__must be a submodule of the selected package.__module__. It unwraps decorators and property getters, ignores generated code such as a dataclass__init__, and only counts functions whose__qualname__is in the owning class's body, so helpers that dataclasses attach fromdataclasses.pyon Python 3.13+ don't count. A class with no such methods, such as an exception subclass, must have itsclassstatement in that module's source (checked withinspect.getsource). Classes from compiled extensions are rejected with an explicit message, since IAST can't patch them.__module__ = "filelock.asyncio"on its async classes, but their code is infilelock/_async_lock/, sofilelock:AsyncFileLockis rejected. It also rejects classes re-exported from another package. Instances, constants and other non-class, non-function attributes get aValueErrornaming the selector.The Filelock endpoint now takes its lock inside a per-request temporary directory, the same pattern
pkg_iniconfig.pyuses for xdist. It previously createdfoobarin the current directory, and Filelock 3.14 doesn't delete it on Unix, so each run left an empty file at the repository root. The endpoint docstring now names the pinned version, 3.14.0.PackageForTestingdocuments themodule:attributeform ofimport_module_to_validate.The local template environment also installs
urllib3, whichtests/appsec/app.pyimports at the top level. CI already gets it throughrequests.Customer impact
None, test-only change.
Testing
appsec_iast_packages -k filelock, in a freshly installed local environment with Filelock 4.3 as latest: passes on Python 3.12, 3.13 and 3.15 and leaves no file in the repository root. On main the same selection fails withNo module named 'filelock._api'. The endpoint check runs against the pinned 3.14 only; the latest version gets the import checks.filelock:BaseFileLockresolves tofilelock._core._lockandfilelock._apirespectively.filelock:AsyncFileLock(4.3),filelock:__version__andcollections:OrderedDictare rejected with aValueError.json:JSONDecoderresolves tojson.decoder.@contextmanager, a dataclass with only fields, a function wrapped by afunctools.wrapsdecorator from another file, and a property-only class all resolve to their defining module. A method-less exception class resolves too. A module-level instance, and classes re-exported with an overridden__module__(with or without methods), are rejected. A slots dataclass resolves too, and a class from a compiled extension (multidict 7.2.1'sMultiDict) is rejected as compiled. Checked on Python 3.12, 3.13 and 3.15, sinceinspect.getsourcelocates classes differently from 3.13 on and dataclasses gain extra methods there.scripts/lint checkspasses.filelock._apialso pass there, so the local runs above are what cover 4.3.Risks
Low. Only selectors containing a colon take the new path, and Filelock is the only package that uses one.
Additional Notes
Discovered while validating https://github.com/DataDog/dd-trace-py/pull/22051 and kept separate, since the Filelock module move is independent of that change. No release note is needed for this test-only change.
Test Management IDs for the Filelock entries this fixes:
DD_46CYMF DD_TD4WM4 DD_ZM3P5R DD_E823VQ DD_DCJ9DQ DD_T91B6L DD_C0WL6V DD_3WVAQ1 DD_VDK12I DD_6VF95K