Skip to content

fix: tighten sign-in, authorization and outbound request checks - #361

Merged
artempartos merged 18 commits into
developfrom
fix/access-hardening
Sep 30, 2026
Merged

artempartos merged 18 commits into
developfrom
fix/access-hardening

Conversation

@artempartos

@artempartos artempartos commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A set of access-control and input-handling fixes, one commit per change.

Sign-in and identity

  • SCIM: a directory PUT can no longer change an existing member's email. It also writes a member's display name only for an active member inside the company's verified domain.
  • Company-scoped sign-in connections attach to existing accounts only when the company's domain is verified.
  • Domain auto-join now requires the sign-in method to prove the address or its domain. For Microsoft this is a upn claim equal to the email, or xms_edov.
  • A company-scoped sign-in connection creates new accounts only for addresses in its own verified domain.
  • A company OIDC connection can be added or enabled only once the company's email domain is verified; the Access page asks for verification first.
  • A company OIDC callback is accepted only in the browser that started the flow.
  • Outbound requests to a company's OIDC issuer (discovery, JWKS, token) go through SafeHttp. The issuer is validated when it is saved, and a failed request now redirects with oauth_failed instead of returning a 500.

Authorization

  • Session and step-run resources treat a missing viewer as a non-owner. Every caller now passes viewer: current_user.
  • /profile/usage shows only the signed-in user; it no longer accepts user_id (a colleague's usage is on the company users screen).
  • Workflow-step sessions follow the run owner's session-sharing preferences like any other session. Previously they were always open to the whole project.
  • /api/v1 enforces the company sign-in policy (SSO-only / step-up) for the company the request acts in. A refusal returns 403 { error: "step_up_required", stepUpUrl }, and apiFetch redirects the browser there.
  • The personal MCP token is bound to the sign-in methods proven when it was issued. "Sign out everywhere", a password change and admin revoke now clear it.
  • Catalog duplicate only targets projects in the current company.
  • The AWS connection API and project-less agent sessions judge the viewer role in the company being acted for.
  • trigger_task_workflow force: true cancels only runs the caller controls.

Containers and integrations

  • Asset and workflow-run-asset names are validated as safe relative paths. Both container download points refuse any path outside /workspace/assets, and nested prior-step outputs now get their directory created.
  • Slack file names are reduced to their basename, and template asset names are validated.
  • The Coder API refuses a host that has no public address instead of falling back to the system resolver. The coder CLI host is checked before each exec.

Deploy notes

  • Migration: adds users.mcp_token_proof_provider_ids (nullable bigint array). It is additive and safe for a rolling deploy.
  • Rolling deploy: during the rollout an old JS bundle may hit a new pod and receive step_up_required. It shows the error toast instead of redirecting, which is harmless.
  • Microsoft (Entra): domain auto-join keeps working only if the app registration emits upn (or xms_edov) in the ID token. Otherwise new Microsoft users are created but do not auto-join any company. Check the app registration before deploying.
  • Personal MCP tokens issued before this change count as a password sign-in. Users of companies that require SSO must regenerate their token.
  • Company OIDC connections saved earlier with a non-https or internal issuer now fail with oauth_failed until an admin edits the issuer.
  • Workflow-step terminals: project members see a step's terminal only if its run owner shares active (or finished) sessions in their profile.
  • Company SSO on an unverified domain can no longer create or link accounts, and a new connection cannot be added or enabled until the domain is verified. Already-linked identities keep working. Before deploying, check for companies that would be affected and verify their domains:
    Company.where(domain_verified_at: nil)
      .joins(:identity_providers).where(identity_providers: { scope: "company" }).distinct.pluck(:id, :name, :email_domain)
  • Coder hosts that resolve only through internal DNS must be listed in URL_SAFETY_TRUSTED_HOSTS.

After deploy

List identities linked through company-scoped connections whose company domain is not verified, and review them:

UserIdentity.joins(identity_provider: :company)
  .where(identity_providers: { scope: "company" }, companies: { domain_verified_at: nil })

Test plan

  • Full backend suite in an isolated Postgres (6905 runs); the 4 tests pinning the old visibility/usage behaviour were updated and re-run green
  • rubocop (2079 files, no offenses), brakeman (no warnings)
  • vitest app/frontend/shared/lib: 126 passed. tsc and eslint report no errors in changed files.
  • CI green

🤖 Generated with Claude Code

artempartos and others added 18 commits September 30, 2026 11:55
…serName

Scimitar applies a PUT through the schema's mutability only and never
consults scim_mutable_attributes, so a full-resource replace reached
scim_user_name= and rewrote the shared User#email. An existing
membership now ignores the incoming address; the rest of the PUT (such
as active: false) still applies.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
… verified domain

User#name is shared across every company a person belongs to, yet any
directory could set it for any membership it provisioned, including an
invited outsider. The name is now applied after save, and only when the
membership is active and the address sits in the company's verified
domain. Owning the domain for SCIM auto-acceptance now also requires
that verification, as domain auto-join already does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
The profile usage page serialized a colleague's sessions without a viewer,
and TerminalSessionResource read a missing viewer as the owner: unredacted
prompt and metadata, the owner-only container URLs, and container tickets
issued in the owner's name.

The page now passes the viewer, and the session, step-run and session-list
resources treat a missing viewer as a stranger and issue no ticket. Every
owner-scoped caller passes `viewer: current_user` so owners keep full data.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
A company-scoped provider could attach itself to an existing account
whenever the address matched the company's claimed email domain, even
before the company had proved it owns that domain. Promotion now also
requires the domain to be verified, matching domain auto-join.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
The catalog's project picker and duplicate looked projects up across every
company the user belongs to, while the role check covered only the current
one, so a copy could land in a project of a company where the user only
views.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
Validate the issuer at save (https, public address, no query or
fragment) and send discovery, JWKS and token requests through SafeHttp
so each is dialed only at the vetted address, over https, without
following redirects. Transport and discovery errors now end the sign-in
as oauth_failed instead of an error page.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
The AWS connection endpoints and project-less session launches had no
company context, so their viewer check fell back to "a viewer in every
company". A viewer of the acting company who works elsewhere could bind a
Bedrock connection there and launch project-less agent sessions billed to
it. The connection endpoints now authorize against the current company, and
a project-less launch against the company the session is billed to;
auth_setup sessions stay open to viewers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
Domain auto-join ran on whatever address an assertion carried, including
Microsoft's `mail`, which any Entra tenant can set to an address at
another organisation's domain. DomainAutoJoin now takes an explicit
`verified:` and joins nobody, not even as a pending request, without it.

Microsoft still never proves the mailbox, but it now reports when the
tenant has shown it owns the address's domain: the address equals the
`upn` (whose suffix Entra requires to be DNS-verified in that tenant) or
`xms_edov` vouches for the `email` claim. That is enough to place
someone in the company owning the same domain, and it never promotes
onto an existing account.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
A non-trusted Coder host with no public IPv4 used to fall back to the
system resolver, whose answer can differ from the one checked when the
URL was saved. Refuse instead, judge literal addresses with
blocked_ip?, and pin the connection to the chosen address rather than
rewriting the URL, so Host, SNI and certificate checks stay the
instance's own. resolve_public_ipv4 now skips every address
blocked_ip? rejects (0.0.0.0/8, 100.64.0.0/10, ...), and the coder CLI
re-checks the URL before each run. Trusted hosts keep using internal
DNS.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
Asset and workflow run asset names are relative paths under
/workspace/assets. Validate them as such, check the resolved target at
both container download points so rows stored before the validation are
skipped instead of written elsewhere, and reduce Slack file names to
their last segment. Template packages with such names are refused.

The workflow step download now creates the parent directory, so nested
prior-step outputs reach the next step.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
…gan it

The login state was signed and single use but tied to nothing on the
client, so a callback link from one person's login completed in any
browser within the state's lifetime. The state nonce is now kept in the
session at the start of the flow and must match on callback before the
server-side entry is consumed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
…trols

trigger_task_workflow with force cancelled the task's in-flight run for any
project writer, while cancel_workflow_run and the run screen reserve that to
the run's starter or a company admin. The forced path now applies the same
rule and returns the same refusal before cancelling anything.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
The web tree sends a session that has not proved a method the company
accepts to step-up; /api/v1 served it anyway. The API now answers 403
step_up_required for the company the request acts in (the project's,
then the session's), naming that company's step-up page, and apiFetch
follows it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
The token reached every company the user belongs to, whatever that
company's sign-in policy. It now records the methods the issuing session
proved and reaches only companies those methods satisfy; a token issued
before this counts as a password sign-in. Signing out everywhere ends
the token too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
A colleague's usage lives on the company users screen, which renders it
for a viewer; the profile page no longer takes a user_id.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
…ied domain

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
…ring

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
…dded or enabled

A company connection now only attaches to accounts inside a verified
domain, so on an unverified one it could never be proved or used; say
so up front instead of failing at sign-in.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
@artempartos
artempartos merged commit 3ef75f4 into develop Sep 30, 2026
7 checks passed
artempartos added a commit that referenced this pull request Sep 30, 2026
The rebase onto #361 put Project.for_user where Project.where(company_id:
membership_company_ids) used to be. for_user spans every active membership,
while membership_company_ids is the token's proven set, so the bare scope
would list the projects of a company whose sign-in policy the token does
not satisfy. The resolution keeps both; this pins it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
artempartos added a commit that referenced this pull request Sep 30, 2026
…w lists (#371)

* feat(assets): enhance asset creation with file validation and error handling

- Added validation to ensure the uploaded file is an actual file and not a string.
- Improved error handling to return specific messages when asset creation fails due to validation errors.
- Updated tests to cover scenarios for successful file uploads, rejection of invalid file types, and handling of validation failures.

Signed-off-by: Evgeniy Yagnenkov <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>

* feat(auth): enhance auth error detection for binary logs

- Introduced a `normalize` method in `AuthErrorDetector` to handle terminal bytes and ensure compatibility with ASCII-8BIT logs, preventing encoding errors during pattern matching.
- Updated the `detect` and `extract_message` methods to utilize the new normalization process.
- Enhanced tests to verify correct behavior when processing binary logs, including scenarios with and without auth banners.

Signed-off-by: Evgeniy Yagnenkov <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>

* feat(tests): optimize project access checks in PersonalMCPTest

- Added a test to ensure that listing projects does not re-check access for each project, reducing unnecessary database queries and improving performance.
- Introduced a test to verify that all projects in a company administered by the caller are included in the project list.
- Updated the `accessible_projects` method to utilize a single query for project access, enhancing efficiency.

Signed-off-by: Evgeniy Yagnenkov <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>

* feat(skills): enhance null byte handling in skill markdown processing

- Updated the `normalize` method to remove null bytes from content, ensuring valid UTF-8 encoding before processing.
- Added tests to verify that null bytes are stripped from skill names and descriptions, preventing errors during database operations.
- Enhanced existing tests to confirm that frontmatter parsing correctly handles content with null bytes.

Signed-off-by: Evgeniy Yagnenkov <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>

* fix(company_membership): prevent refresh on errored credentials in agent model fetching

- Updated the `agent_models_for_props` method to return an empty array if the credential is marked as errored, preventing unnecessary refresh attempts and associated errors.
- Added a test to verify that the method does not attempt to refresh a credential already marked as an error, ensuring stability in the agent model loading process.

Signed-off-by: Evgeniy Yagnenkov <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>

* feat(workflows): optimize workflow run statistics retrieval

- Introduced a new method `attach_run_stats` in the `Workflow` model to efficiently gather run statistics (count, last run time, last state, and active status) in a single query, reducing database load.
- Updated `WorkflowResource` to utilize the new run statistics instead of loading runs directly, improving performance and reducing unnecessary data loading.
- Modified various controllers to leverage the new statistics, ensuring that workflows are rendered with accurate run data without excessive queries.
- Enhanced tests to verify the correctness of the new run statistics functionality and ensure that workflows are displayed correctly without counting runs per workflow in certain contexts.

Signed-off-by: Evgeniy Yagnenkov <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>

* test(mcp): keep list_projects to the companies the token was issued for

The rebase onto #361 put Project.for_user where Project.where(company_id:
membership_company_ids) used to be. for_user spans every active membership,
while membership_company_ids is the token's proven set, so the bare scope
would list the projects of a company whose sign-in policy the token does
not satisfy. The resolution keeps both; this pins it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>

---------

Signed-off-by: Evgeniy Yagnenkov <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
Co-authored-by: Artem Petrov <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
aixle-com Bot pushed a commit that referenced this pull request Nov 26, 2026
aixle-com Bot pushed a commit that referenced this pull request Nov 26, 2026
artempartos pushed a commit that referenced this pull request Nov 27, 2026
* feat(tasks): edit task title, description and properties separately (#361)

Refs #361

Signed-off-by: Aixle Flow <[email protected]>

* fix(frontend): satisfy lint and update drawer title test for single header title

Signed-off-by: Aixle Flow <[email protected]>

* fix(frontend): apply prettier formatting to task description color

Signed-off-by: Aixle Flow <[email protected]>

* fix(tasks): autosave properties, keep pencils for title and description

Refs #361

Signed-off-by: Aixle Flow <[email protected]>

* test(tasks): drop stale properties assertion from title edit test

Refs #361

Signed-off-by: Aixle Flow <[email protected]>

---------

Signed-off-by: Aixle Flow <[email protected]>
Co-authored-by: Aixle Flow <[email protected]>
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.

1 participant