Skip to content

test: setattr/delattr hardening - #7291

Merged
fracasula merged 8 commits into
masterfrom
setattr-delattr-hardening-contract
Aug 31, 2026
Merged

fracasula merged 8 commits into
masterfrom
setattr-delattr-hardening-contract

Conversation

@fracasula

@fracasula fracasula commented Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Contract tests for this PR, which routes every sandbox write (obj.attr = v, del obj.attr, setattr(), delattr()) through a new write guard.

WARNING: The tests should pass once we have a new PYT release.

They live in integration_test/pytransformer_contract/security_hardening_contract_test.go and must merge together with the pytransformer PR.

What is pinned

The write guard defaults to shadow (record and allow), so both sides of the switch are covered across the container boundary:

  • TestWriteGuardShadowContract — at the shipping default the write lands, the transformation runs to completion, transformer_write_guard_unsafe_total{kind} records it, and the alerted-on security series stays at zero.
  • TestWriteGuardEnforceContract / TestWriteGuardDelattrContract — under SANDBOX_WRITE_GUARD_ENFORCE=true a write to a module, a foreign class, or a reserved name is refused and lands on transformer_security_violations_total.
  • TestWriteGuardLibraryOwnershipContract — a transformation writing to its own library records nothing, the direction that decides whether the counter is readable at all.
  • TestWriteGuardOwnershipRegistryContract — ownership is keyed by identity, so an unhashable class is not over-blocked and a forged __hash__/__eq__ cannot launder ownership.
  • TestWriteGuardCounterUnitContract — the counter counts refused writes, not failed transformations.
  • TestTestFlowSecurityMetricsContract / TestTestFlowEnforceContract — /test and /testRun replay their security signals onto the transformer_test_flow_* twins, never the production series.
  • TestGetattrAndModuleGuardContract — the getattr value guard and the raw __getattribute__ / __getattr__ block.
  • TestFactoryReprRiskContract — the new shadow-only telemetry: a transformation that both builds a factory-made class (namedtuple, three-argument type()) and renders text is flagged on transformer_factory_class_repr_risk_total, while a factory class that is never rendered stays quiet. It sizes the follow-up __module__ work and changes no behaviour.

The write-guard, preview-twin and factory-telemetry tests are candidate-only: the guard and those metrics are new, so no released baseline image exports them to compare against.

Linear Ticket

< Fixes PIPE-3322 >

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

Test-only change. It locks the contract that the pytransformer sandbox blocks these escapes, that the write guard refuses non-user-owned writes under enforce while changing nothing at the shadow default, and that preview traffic never reaches the production security series.

…enforce blocks

getattr and import guards now enforce unconditionally in the candidate
rudder-pytransformer image, so SANDBOX_GETATTR_GUARD_ENFORCE and
SANDBOX_IMPORT_GUARD_ENFORCE no longer exist. Drop both env args from the
candidate startup in TestGetattrAndModuleGuardContract and update the two
inline comments that referenced them; the existing assertBlockedOnCandidate
subtests are unchanged since the blocks now happen by default.

Add TestWriteGuardEnforceContract, a candidate-only sibling test that starts
a second candidate with SANDBOX_WRITE_GUARD_ENFORCE=true and asserts a
module write (json.loads = None) and a foreign-class write
(setattr(requests.exceptions.HTTPError, ...)) are both blocked with a clean
400 mentioning "not allowed" and "non-user-owned". Both targets are reached
by plain top-level import + attribute read, deliberately avoiding
socket.socket, which the getattr guard already blocks at the read step
(requests.utils.socket is not on the value guard's reachability allow-list)
and would therefore exercise the wrong guard's error message.

assertBlockedOnCandidate is promoted from a closure to a package-level
helper (parameterized by *bcTestEnv) so both tests share one assertion
definition.
@fracasula
fracasula force-pushed the setattr-delattr-hardening-contract branch from dea89a5 to d75af2d Compare August 19, 2026 08:42
@fracasula
fracasula marked this pull request as ready for review August 26, 2026 11:25
@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.36%. Comparing base (6f96eea) to head (46a2911).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7291      +/-   ##
==========================================
- Coverage   79.81%   79.36%   -0.45%     
==========================================
  Files         604      604              
  Lines       67687    67687              
==========================================
- Hits        54022    53722     -300     
- Misses      10482    10808     +326     
+ Partials     3183     3157      -26     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@fracasula
fracasula merged commit 2855af4 into master Aug 31, 2026
151 of 159 checks passed
@fracasula
fracasula deleted the setattr-delattr-hardening-contract branch August 31, 2026 07:04
This was referenced Aug 31, 2026
itsmihir pushed a commit that referenced this pull request Aug 31, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.85.0-rc.1](v1.84.0...v1.85.0-rc.1)
(2026-08-31)


### Features

* backend config v2 resolver with stub mapper
([#7275](#7275))
([267b973](267b973))
* **warehouse:** clickhouse v2 connection and schema
([#7301](#7301))
([2eb1fa6](2eb1fa6))
* **warehouse:** clickhouse v2 ddl operations
([#7302](#7302))
([f2887c5](f2887c5))
* **warehouse:** clickhouse v2 loading
([#7303](#7303))
([3e48618](3e48618))
* **warehouse:** enable the clickhouse v2 driver behind a flag
([#7311](#7311))
([3ce1da5](3ce1da5))


### Bug Fixes

* race conditions while counting initial pending events can cause wrong
counting
([#7292](#7292))
([3efa718](3efa718))
* replay destinations not using the config corresponding to their
connected source type
([#7307](#7307))
([ee7aa93](ee7aa93))
* **router:** abort router-transform on proactive invalid_grant instead
of retrying (INT-6779)
([#7175](#7175))
([4d7348d](4d7348d))
* tracking plan merged config is cached without its event type
([#7314](#7314))
([624dd5c](624dd5c))


### Miscellaneous

* setattr/delattr hardening
([#7291](#7291))
([2855af4](2855af4))
* sync release v1.84.0 to main branch
([#7306](#7306))
([fa102b7](fa102b7))
* webhook reasons
([#7294](#7294))
([c298d59](c298d59))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
itsmihir pushed a commit that referenced this pull request Sep 1, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.85.0](v1.84.0...v1.85.0)
(2026-08-31)


### Features

* backend config v2 resolver with stub mapper
([#7275](#7275))
([267b973](267b973))
* **warehouse:** clickhouse v2 connection and schema
([#7301](#7301))
([2eb1fa6](2eb1fa6))
* **warehouse:** clickhouse v2 ddl operations
([#7302](#7302))
([f2887c5](f2887c5))
* **warehouse:** clickhouse v2 loading
([#7303](#7303))
([3e48618](3e48618))
* **warehouse:** enable the clickhouse v2 driver behind a flag
([#7311](#7311))
([3ce1da5](3ce1da5))


### Bug Fixes

* race conditions while counting initial pending events can cause wrong
counting
([#7292](#7292))
([3efa718](3efa718))
* replay destinations not using the config corresponding to their
connected source type
([#7307](#7307))
([ee7aa93](ee7aa93))
* **router:** abort router-transform on proactive invalid_grant instead
of retrying (INT-6779)
([#7175](#7175))
([4d7348d](4d7348d))
* tracking plan merged config is cached without its event type
([#7314](#7314))
([624dd5c](624dd5c))


### Miscellaneous

* setattr/delattr hardening
([#7291](#7291))
([2855af4](2855af4))
* sync release v1.84.0 to main branch
([#7306](#7306))
([fa102b7](fa102b7))
* webhook reasons
([#7294](#7294))
([c298d59](c298d59))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants