Fixing Low Integrity Labels Left Behind by DSH workspace-write Sandbox on Windows

Preface

DSH’s workspace-write sandbox enforces a Low integrity label on the workspace root directory and its entire subtree on Windows. These labels persist on the file system after the session ends. Programs launched from that directory run with Low integrity, which can cause configuration directory write failures, missing tray icons, SmartScreen prompts, Electron application startup crashes, and denied workspace file deletion. xia-sc/dsh-workspace-integrity is a Windows-only DSH plugin package that remediates these residual Low integrity labels and provides a Chinese-language integrity panel, a workspace_integrity agent tool, rollback records, and automatic cleanup.

Plugin Overview

Developed by the maintainer xia-sc, this plugin is categorized under admin-security. Its plugin registration name is @xia-sc/dsh-workspace-integrity, and its npm package name is @xia-sc/dsh-workspace-integrity. It supports only the Windows platform, and the panel body is fixed to Chinese. The plugin provides three remediation entry points: automatic cleanup, the UI panel, and the agent tool. All three share the same host implementation to ensure consistent behavior.

Core Features

  • Automatic cleanup: When a session switches to danger-full-access mode, the plugin performs a one-time label restoration on the current workspace. If the root directory is already Medium, it idempotently skips—no scanning, no record writing, no tree traversal.
  • Integrity panel: Select “Integrity” from the session header tab row to view the current workspace status. The panel supports scanning (read-only view of Low objects, S-1-4 sandbox ACEs, and Everyone delete-denial ACEs), remediation (requires a second confirmation; a third confirmation is needed if the session is still in workspace-write mode), verification, and rollback. The panel also displays the timestamp and source of the last cleanup for this workspace.
  • Agent tool: Provides the workspace_integrity command with actions including scan, fix, verify, rollback, and records. Parameters include path (absolute path; defaults to the current session workspace if omitted), removeAces (removes non-inherited S-1-4-* ACEs and Everyone delete-denial ACEs), allFiles (scans all files), excludeDirs (an array of directory names or relative path prefixes to skip for this run), fast (skips pre-scan, only recursively resets the root label, does not remove ACEs), force (forces remediation while the session is still in workspace-write), and whatIf (returns a plan only; no records written, no ACL changes).
  • Rollback records: Before remediation, the DACL of the root directory and the DACL of each affected object are saved. Records include the source (automatic/manual/tool) and whether a pre-scan was performed. Rollback restores the root DACL and Low labels from the record.
  • Security gate and concurrency protection: If the calling session is in workspace-write mode and force is not explicitly passed, the remediation is rejected. Only one remediation is allowed per workspace, both in-process and cross-process, enforced via a lock file for exclusivity.
  • Status visibility and cooldown persistence: The panel displays the “last cleanup” timestamp and source for the workspace; the automatic cleanup cooldown state is written to %DSH_HOME%\dsh-workspace-integrity\workspace-integrity.state.json, preventing re-triggering after plugin reload.
  • Dry run and dangerous path protection: Using whatIf: true or the script -WhatIf flag returns a plan without modifying ACLs. Dangerous paths such as drive roots, %SystemRoot%, %ProgramFiles%, %ProgramData%, and the user profile root are rejected by default.
  • Scan scope exclusion and plugin detail page settings: .git, .hg, and .svn directories are skipped by default; exclusions can be configured by directory name or relative path prefix. On the plugin detail page, you can toggle automatic cleanup, scan all files, remove sandbox ACEs during remediation, and edit excluded directories. Saved settings are written to %DSH_HOME%\dsh-workspace-integrity\config.json and take effect immediately.

Installation and Activation

Install from npm (recommended):

plugin_manager({ action: 'install_bundle', target: '@xia-sc/dsh-workspace-integrity' })

You can also enter the same package name under Plugins → Add Plugin.

Install from a local directory (development):

plugin_manager({ action: 'install_bundle', target: 'E:\\path\\to\\dsh-workspace-integrity' })

Local directory installation links the entire directory. After making changes, you must restart dsh (or let the plugin manager reload) to load the new host module and browser bundle. The plugin is enabled by default after installation.

Typical Usage

Integrity panel workflow:

  1. Open any session and select “Integrity” from the header tab row (Conversation / Trace / …).
  2. The panel opens with the current session’s workspace by default (follows working_directory switches).
  3. Click “Scan” (read-only) to view Low objects, S-1-4 sandbox ACEs, and Everyone delete-denial ACEs.
  4. Click “Fix”—this requires a second confirmation (click again within 4 seconds). If the session is still in workspace-write mode, the button changes to “Fix Anyway (will interrupt this session’s writes)” and requires a third confirmation.
  5. Use the rollback records to restore the root DACL and Low labels per record.

Agent tool examples:

workspace_integrity action=scan    path=E:\my-workspace
workspace_integrity action=fix     path=E:\my-workspace
workspace_integrity action=verify  path=E:\my-workspace
workspace_integrity action=records
workspace_integrity action=rollback backupDir=C:\Users\me\AppData\Local\dsh-workspace-integrity\backup-...

Configuration

The plugin configuration file is located at %DSH_HOME%\dsh-workspace-integrity\config.json and is auto-generated on first mount:

{
  "autoClean": true,
  "removeAces": false,
  "scanAllFiles": false,
  "excludeDirs": [".git", ".hg", ".svn"]
}

Configuration precedence (lowest to highest): built-in defaults → plugin config in the profile’s cordis.patch.yml → config.json in the data directory. Normally, modify settings on the plugin detail page or edit config.json directly. cordis.patch.yml is only responsible for inserting the plugin into the loader tree and no longer writes config, avoiding mutual overrides between the two locations. Changes saved on the detail page take effect immediately; manual file edits require restarting DSH (or reloading the plugin) to take effect.

Configuration options:

  • autoClean: Defaults to true. Automatically cleans the current workspace when a session switches to danger-full-access.
  • removeAces: Defaults to false. During remediation, also removes non-inherited S-1-4-* ACEs and Everyone delete-denial ACEs.
  • scanAllFiles: Defaults to false. Scans all files rather than only common executable extensions.
  • excludeDirs: Defaults to ['.git', '.hg', '.svn']. Skips these directories (matched by directory name at any level, or by relative path prefix from the root); the root directory itself is always checked.

The panel uses these values as initial checkbox states. A single operation can override them, but changes are not written back to the configuration. The panel footer displays the currently active configuration file path.

Behavioral Design Notes

  • Automatic cleanup listens for the sandbox/mode event; it idempotently skips if the root label is already Medium.
  • Automatic cleanup, the panel, and the tool all resolve the directory through the same sessionWorkspace() function (working_directory takes priority, falling back to the session launch directory).
  • Manual remediation returns “no changes” directly when not removing ACEs and the root is not Low. fast and removeAces cannot be combined (fast does not pre-scan); the script rejects this combination, and the host explicitly downgrades removeAces on the fast path with a warning.
  • fix is rejected by the host when the calling session is in workspace-write and force is not passed.
  • fix, rollback, and automatic cleanup share a per-workspace lock (in-process Map + cross-process lock file); running the script directly uses a separate .lock mutex.
  • If label restoration fails or the root remains Low, ACE removal is not proceeded with, and acesSkipped is written into the result and record.
  • Non-fast remediation reports success only if a re-scan shows low, sandboxSid, and everyoneDeny all at 0; scan truncation also counts as incomplete.
  • Rollback records include requestedRemoveAces/removeAces/fast/trigger/truncated/removedAces/acesSkipped/ok. Each affected object’s DACL is saved before removal.
  • excludeDirs takes effect before entering subtrees. Excluded directories are not counted, not reported as hits, and not removed; the root directory itself is always checked.
  • The panel renders at most 500 entries in the hit list; beyond that, it shows “Showing first N entries only.”

Known Limitations

  • Windows only: Modifying mandatory integrity labels requires WRITE_OWNER or SeRelabelPrivilege; drive roots owned by Administrators will return Access denied and require an elevated shell.
  • Do not remediate while a workspace-write session is still writing to the workspace: Low tokens inside the sandbox require Low labels to write; changing to Medium prematurely will cause that session to lose write permission. Automatic cleanup only triggers after switching to danger-full-access.
  • DSH does not re-label: Workspace authorization is cached per provider lifecycle. Sessions continuing to use workspace-write after remediation will keep failing to write until DSH is restarted or a different workspace is used.
  • Idempotent skip: Manual remediation scans the subtree first and only skips if no Low objects exist in the entire tree. If the root is Medium but child objects still have Low labels, remediation proceeds. fast automatic cleanup does not pre-scan and only checks the root; residual child object labels require manual remediation.
  • removeAces modifies DACLs: Only explicit ACEs matching the DSH sandbox shape are removed (S-1-4-x-y / S-1-4-x-y-1 allow, GRANT_MASK, OI|CI; Everyone’s FILE_DELETE_CHILD deny, CI). Inherited entries are left to the parent. Object DACLs are saved before removal and can be restored via rollback. This may still restore a restricted process’s ability to delete files outside the workspace—use only when you genuinely intend to hand over the directory.
  • Rollback records: The root DACL is saved, and each affected object’s DACL is saved before ACE removal; rollback restores both and re-scans remainingLow. Records from before 0.4.0 lack object DACLs, and those removals cannot be rolled back.
  • Automatic cleanup does not remove ACEs: Even if removeAces is enabled in configuration, the fast path will not remove them, and the log will note this.
  • Excluded directories are not cleaned: Directories in excludeDirs are neither scanned nor removed; results and records mark them as excluded. Do not interpret “skipped” as “remediated.”
  • Truncation and failure: When MaxObjects truncation occurs, the result is marked truncated with ok=false, and only scanned objects are remediated. Label restoration failure, root still being Low, or unreadable DACLs all prevent the remediation from reporting success.
  • Dangerous paths: Drive roots, %SystemRoot%, %ProgramFiles%, %ProgramData%, and the user profile root are rejected by default; on the script side, only an explicit -AllowDangerousRoot flag can bypass this.
  • Encoding: Scripts are saved as UTF-8 with BOM, and Chinese text matching that depends on the local code page has been removed; icacls failures are judged solely by exit code.
  • Privileges: The plugin itself does not elevate privileges and does not disable the sandbox.

Applicable Scenarios and Cautions

This plugin is suitable for developers using DSH on Windows to build intelligent agents or debug workspace-related features. Before use, review the source code and license to confirm compliance with your security and compliance requirements. The plugin runs with the current DSH process privileges; modifying mandatory integrity labels requires WRITE_OWNER or SeRelabelPrivilege. Drive roots owned by Administrators will return Access denied and require an elevated shell. Do not remediate while a workspace-write session is still writing to the workspace, as this will cause that session to lose write permission.

Summary

xia-sc/dsh-workspace-integrity provides a complete set of remediation and monitoring capabilities for handling residual Low integrity labels left by DSH’s workspace-write sandbox on Windows, including automatic cleanup, a UI panel, an agent tool, and rollback records. It ensures consistent behavior through a shared host implementation and provides configuration and dry-run capabilities for controlled use. See the plugin detail page and GitHub repository: https://www.skillhub.cn/plugins/xia-sc/dsh-workspace-integrity and https://github.com/xia-sc/dsh-workspace-integrity.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye