Skip to content

fix(declarative): require AIRBYTE_ENABLE_UNSAFE_CODE to instantiate Custom* components from YAML - #1076

Merged
Aaron ("AJ") Steers (aaronsteers) merged 3 commits into
mainfrom
devin/1784682886-gate-custom-component-code-exec
Jul 22, 2026
Merged

Aaron ("AJ") Steers (aaronsteers) merged 3 commits into
mainfrom
devin/1784682886-gate-custom-component-code-exec

Conversation

@aaronsteers

@aaronsteers Aaron ("AJ") Steers (aaronsteers) commented Jul 22, 2026 •

Copy link
Copy Markdown
Member

Summary

Hardens the custom-component path so that instantiating a Custom* component honors the same AIRBYTE_ENABLE_UNSAFE_CODE gate that already protects injected components.py source.

Previously, only injected components.py source was gated (in get_registered_components_module). The class_name resolution path in ModelToComponentFactory.create_custom_component was not gated: it resolves an arbitrary fully-qualified class_name via importlib.import_module + getattr and then calls it with manifest-supplied kwargs, regardless of AIRBYTE_ENABLE_UNSAFE_CODE. This meant a manifest could cause arbitrary importable code to be executed even in environments where custom code execution is meant to be disabled.

Fix — add a guard at the top of create_custom_component, before the class is resolved/imported:

def create_custom_component(self, model, config, **kwargs):
    if not custom_code_execution_permitted():
        raise AirbyteCustomCodeNotPermittedError
    custom_component_class = self._get_class_from_fully_qualified_class_name(model.class_name)
    ...

This centralizes enforcement for every Custom* model type (they all route through create_custom_component), and the check fires before any import happens.

Tests

  • New regression test test_create_custom_component_requires_custom_code_enabled asserts AirbyteCustomCodeNotPermittedError is raised when the env var is unset — both for a bundled custom-component class and for an arbitrary importable callable — verifying the gate fires before import.
  • Unit tests exercise custom components extensively; added an autouse fixture in unit_tests/conftest.py that enables AIRBYTE_ENABLE_UNSAFE_CODE by default, reflecting the new precondition for building custom components. Gate-focused tests opt out via their own monkeypatch.

Ran unit_tests/sources/declarative custom-component tests, the injected-code gate tests, and the previously-affected source/manifest suites locally — all green. ruff format/ruff check clean.

Relates to advisory GHSA-g35w-6r6v-h4r7. Draft pending maintainer review of disclosure timing.

Link to Devin session: https://app.devin.ai/sessions/091d09a568eb48018f82dd6ed27d2445
Requested by: Aaron ("AJ") Steers (@aaronsteers)

Summary by CodeRabbit

  • Bug Fixes

    • Added a safety check that blocks custom component code from running unless explicitly permitted.
    • Custom components now fail with a clear permission error when custom code execution is disabled.
    • Prevented blocked components from being resolved or imported before permission is verified.
  • Tests

    • Added coverage for custom-code restrictions and safe environment cleanup during declarative component tests.

Important

Auto-merge enabled.

This PR is set to merge automatically when all requirements are met.

…ustom components

Co-Authored-By: AJ Steers <aj@airbyte.io>
Copilot AI review requested due to automatic review settings July 22, 2026 01:15
@devin-ai-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@github-actions

Copy link
Copy Markdown

👋 Greetings, Airbyte Team Member!

Here are some helpful tips and reminders for your convenience.

💡 Show Tips and Tricks

Testing This CDK Version

You can test this version of the CDK using the following:

# Run the CLI from this branch:
uvx 'git+https://github.com/airbytehq/airbyte-python-cdk.git@devin/1784682886-gate-custom-component-code-exec#egg=airbyte-python-cdk[dev]' --help

# Update a connector to use the CDK from this branch ref:
cd airbyte-integrations/connectors/source-example
poe use-cdk-branch devin/1784682886-gate-custom-component-code-exec

PR Slash Commands

Airbyte Maintainers can execute the following slash commands on your PR:

  • /autofix - Fixes most formatting and linting issues
  • /poetry-lock - Updates poetry.lock file
  • /test - Runs connector tests with the updated CDK
  • /prerelease - Triggers a prerelease publish with default arguments
  • /poe build - Regenerate git-committed build artifacts, such as the pydantic models which are generated from the manifest JSON schema in YAML.
  • /poe <command> - Runs any poe command in the CDK environment
📚 Show Repo Guidance

Helpful Resources

📝 Edit this welcome message.

This comment was marked as resolved.

Copilot AI review requested due to automatic review settings July 22, 2026 01:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread unit_tests/conftest.py Outdated
@aaronsteers
Aaron ("AJ") Steers (aaronsteers) marked this pull request as ready for review July 22, 2026 01:22
@aaronsteers Aaron ("AJ") Steers (aaronsteers) changed the title fix(declarative): require AIRBYTE_ENABLE_UNSAFE_CODE to instantiate custom components fix(declarative): require AIRBYTE_ENABLE_UNSAFE_CODE to instantiate custom components Jul 22, 2026

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Custom component creation now requires explicit custom-code permission before class resolution. Declarative test fixtures enable custom code by default, and tests verify disabled execution raises the permission error before imports occur.

Changes

Custom code execution gate

Layer / File(s) Summary
Custom component permission gate
airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py
create_custom_component checks custom_code_execution_permitted() and raises AirbyteCustomCodeNotPermittedError before resolving or importing the requested class.
Permission gate test coverage
unit_tests/sources/declarative/parsers/test_model_to_component_factory.py, unit_tests/sources/declarative/conftest.py, unit_tests/legacy/sources/declarative/conftest.py
Declarative test fixtures temporarily enable custom code, while parametrized tests disable the environment variable and assert rejection occurs before class resolution.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: copilot

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: gating declarative Custom* YAML instantiation behind an unsafe-code environment flag.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch devin/1784682886-gate-custom-component-code-exec

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

PyTest Results (Fast)

4 133 tests  +2   4 121 ✅ +2   7m 40s ⏱️ -9s
    1 suites ±0      12 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 2dee31c. ± Comparison against base commit cc951be.

♻️ This comment has been updated with latest results.

Copilot AI review requested due to automatic review settings July 22, 2026 01:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@aaronsteers Aaron ("AJ") Steers (aaronsteers) changed the title fix(declarative): require AIRBYTE_ENABLE_UNSAFE_CODE to instantiate custom components fix(declarative): require AIRBYTE_ENABLE_UNSAFE_CODE to instantiate Custom* components from YAML Jul 22, 2026
@github-actions

Copy link
Copy Markdown

PyTest Results (Full)

4 136 tests   4 124 ✅  11m 42s ⏱️
    1 suites     12 💤
    1 files        0 ❌

Results for commit 2dee31c.

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