Phase 1: Security Hardening - #7
Merged
Merged
Conversation
- S1: Remove --token CLI argument (visible in ps aux), add interactive hidden prompt and KBC_TOKEN env var support for project add/edit - S2: Add HTTPS-only URL validation on ProjectConfig via field_validator - S3: Set config directory permissions to 0o700 (was default umask) - S4: Truncate API error messages to 500 chars to prevent Rich markup injection and excessive output - S5: URL-encode component_id, config_id, job_id in API paths to prevent path traversal attacks - S6: Replace assert in production code with proper ConfigError handling
Closed
8 tasks
4 tasks
Matovidlo
added a commit
that referenced
this pull request
Jun 15, 2026
…, dedup Thermo-nuclear review follow-ups (behavior-preserving): - #1/#6: move inline nfpm loop -> build/package/linux/build_packages.sh and the zip+sha256 -> build/package/zip_binary.sh (explicit per-OS archiver); workflow is now pure orchestration. - #2: .github/actions/setup-build composite (uv + optional Node) replaces the repeated setup preamble in pypi/freeze. - #3: index.sh deb/rpm/apk collapsed into a publish_repo() helper + per-format indexers. - #5: sign.sh parses the Azure token with jq instead of a sed regex. - #7: nfpm.yaml notes it's rendered via envsubst. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Matovidlo
added a commit
that referenced
this pull request
Jun 17, 2026
…, dedup Thermo-nuclear review follow-ups (behavior-preserving): - #1/#6: move inline nfpm loop -> build/package/linux/build_packages.sh and the zip+sha256 -> build/package/zip_binary.sh (explicit per-OS archiver); workflow is now pure orchestration. - #2: .github/actions/setup-build composite (uv + optional Node) replaces the repeated setup preamble in pypi/freeze. - #3: index.sh deb/rpm/apk collapsed into a publish_repo() helper + per-format indexers. - #5: sign.sh parses the Azure token with jq instead of a sed regex. - #7: nfpm.yaml notes it's rendered via envsubst. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
martinsifra
added a commit
that referenced
this pull request
Aug 26, 2026
The big one (#2, upgraded): the diff sides' wire shape was WRONG in the implementation and in the test fixtures that defined it. Verified against connection (ConfigurationVersionResponse + ConfigurationDiffData OA schemas, now recorded in the notes wire-truth table): each side is {version, isDeleted, diff: {name, description, changeDescription, isDisabled, configuration, rows}} -- content NESTED under diff, version/deletion as side metadata. The classification and both take modes now read the envelope; the flat-side code would have been dead on arrival against the live API. #1: resolve_conflict no longer takes branch_id -- it derives the branch from the MR itself (branches.branchFromId), so the conflict-set guard and the branch being written to can never disagree; a caller-supplied id could point the REPLACing rebase at an unrelated dev branch the guard never checked. A published/canceled MR (null branchFromId) is refused readably. #3: take=theirs of a deleted side collapses to the delete resolution, symmetric with ours ('production deleted it, dev changed it' is a live conflict shape). #4: deletion surfaces as top-level ours_deleted/theirs_deleted booleans on get_config_diff (None = side never existed) -- it is side metadata, not a content path. #5: a 'both' row where the sides agree on the identical value carries agreed: true -- agreement, not a conflict hotspot. #2 (message half): a take side missing required envelope keys is reported as a backend contract violation pointing at the resolved-body workaround, not as caller error. #6: wire ids compared via _same_id / int-coerced (find_merge_request_for_ branch, merge()'s was_active) -- a string-serialized branchFromId can no longer silently defeat the post-merge cleanup. #7: the feature pre-flight raises FeatureNotEnabledError carrying the new ErrorCode.FEATURE_NOT_ENABLED (value matches the string SearchService already emits; categorized 'configuration' like PAYG_NOT_AVAILABLE). #8: ConfigError imported from ..errors like every other service; the isDefault scan hoisted to services.base.find_default_branch_id and the copies in config/sync/workspace services migrated (lib.py keeps its own loop -- the SDK facade does not import the services layer); verify_token is skipped when the server already serialized viewer (the polyfill's cost dies with the polyfill); list --state validates against the closed vocabulary instead of returning a silent count: 0 on a typo. #9: test imports hoisted (no mid-file noqa), mocks spec'd at the L3 seam (KeboolaClient + MergeRequests -- a renamed L3 method now fails the tests), and regression tests added for every finding (82 tests total). Doc drift: layer2/layer3 references updated to BRANCHES_MERGE_REQUESTS_ FEATURE, the layer3 open nit closed, tokens.py line ref fixed. Review: tasks/pr-703-review.md (2026-08-27). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
martinsifra
added a commit
that referenced
this pull request
Aug 27, 2026
…actions, derive_state honesty [DMD-1899] Adversarial review of every wire assumption against Connection source (tasks/pr-703-opus-wire-review.md): 7 CONFIRMED, 3 MISMATCH. The fixes: 409 mapping (finding #4): the conflict 409 is NOT code-less -- an earlier reading missed ExceptionConverter, which serializes MergeValidationException's own string code storage.mergeRequests.validation top-level as `code`, plus the conflicting configurations in `params.errors`. _remap_merge_conflict now matches BOTH codes explicitly (code-less 409 falls back to conflict for older stacks; a 409 with any OTHER code passes through unmapped instead of being confidently mislabeled a conflict), and http_base surfaces `params` as details.api_error_params so the conflict list travels with the error instead of demanding a second round trip. Stale 'carries no code' claims corrected in errors.py, the L3 docstring, error-codes.md, the notes wire-truth table and the RFC. allowed_actions (finding #7): `approve` removed from the `approved` tuple -- the transition's sole `from` place is in_review; from approved the backend answers 422 (the UI button offering it there is wrong). `update` added to in_merge (the server blocks update only in terminal states). Docstring records the AddApprovalGuard gating and that with the non-SOX default of 0 required approvals, approve is 422 in every state and in_review itself is unreachable. derive_state honesty (finding #10, the significant one): reviewers[].status is populated only within a review round anchored by a review_requested activity event -- which skip_review never writes -- and explicit reviewers shadow every non-reviewer's decision (the creator can never BE a reviewer). So in a default non-SOX project the rejected / self-closed derivations never fire; the UI badge has the identical blind spot, since our table is its port. Documented in the docstring and the RFC rather than re-derived from the activity log client-side: the reliable fix is server-side (commented on DMD-1988 -- derive from the activity log, not reviewers[]). Sharp edges from confirmed items: a take side with a null/empty `name` (nullable in the diff envelope, required non-empty by the rebase validator) is refused as a contract violation instead of sailing into a server 400; _branch_from_id_of documents that its null check is racy (branchFromId is nulled by the FK when the async branch delete lands, not by the state change); the viewer docstring notes detail/conflicts require an admin token anyway (MergeRequestVoter). Regression tests for each fix; 87 service tests total. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implementation Summary
Fix critical and medium security vulnerabilities: token exposure, URL validation, directory permissions, error message sanitization, path traversal prevention, and assert removal.
Acceptance Criteria
--tokenis NOT accepted as CLI argument forproject addandproject editKBC_TOKENenv var or interactive hidden prompthttp://andfile://URLs are rejected atproject addtime with clear errorhttps://URLs are accepted0o700permissionscomponent_id,config_id,job_idare URL-encoded in API pathsassertstatements remain in production code (only in tests)Tests
test_project_add_token_from_env-- token from KBC_TOKEN env vartest_project_add_token_interactive-- interactive hidden prompttest_project_add_rejects_http_url-- http:// rejectedtest_project_add_rejects_file_url-- file:// rejectedtest_project_add_accepts_https_url-- https:// acceptedtest_config_dir_permissions-- directory 0o700test_api_error_message_truncation-- long response truncated to 500 charstest_url_path_encoding_*-- special chars in IDs encodedFiles Changed
src/keboola_agent_cli/commands/project.py-- Remove --token CLI option, add _resolve_token() with env var + interactive promptsrc/keboola_agent_cli/models.py-- Add @field_validator('stack_url') enforcing https:// schemesrc/keboola_agent_cli/config_store.py-- mkdir mode=0o700src/keboola_agent_cli/client.py-- Truncate api_message to 500 chars, URL-encode path paramssrc/keboola_agent_cli/manage_client.py-- Truncate api_message to 500 charssrc/keboola_agent_cli/services/project_service.py-- Replace assert with ConfigErrortests/test_cli.py-- Updated all project add/edit tests, added security teststests/test_client.py-- Added truncation and URL encoding teststests/test_config_store.py-- Added directory permission teststests/test_models.py-- Added URL validation tests