Skip to content

fix: harden cookie flags, sanitize Genie markdown output, fix remote tunnel#216

Merged
pkosiec merged 3 commits intomainfrom
pkosiec/impr-security
Mar 26, 2026
Merged

fix: harden cookie flags, sanitize Genie markdown output, fix remote tunnel#216
pkosiec merged 3 commits intomainfrom
pkosiec/impr-security

Conversation

@pkosiec
Copy link
Copy Markdown
Member

@pkosiec pkosiec commented Mar 25, 2026

Summary

  • Fix dev-remote tunnel crash: copy HTML template files (index.html, wait.html, denied.html) to dist/ during build via tsdown copy config instead of a shell cp command — they were missing because tsdown only transpiles TypeScript
  • Set httpOnly: true and secure: true on the dev-tunnel-id cookie in the remote tunnel manager. The cookie is only read server-side (HTTP requests + WebSocket upgrades), never by client-side JS.
  • Add DOMPurify sanitization to Genie chat message markdown rendering (dangerouslySetInnerHTML) as defense-in-depth against potential XSS via API content.
  • Revert PR template artifact CI step from npm ci back to npm installprepare-pr-template.ts rewrites dependencies to file: tarballs, which will never match the lockfile copied from template/.

Test plan

  • CI passes
  • Build produces HTML files in dist/plugins/server/remote-tunnel/
  • Verify dev tunnel still works with the updated cookie flags in a deployed environment
  • Verify Genie chat messages still render markdown correctly

@pkosiec pkosiec force-pushed the pkosiec/impr-security branch from f8c9a2e to e217d79 Compare March 25, 2026 18:17
- Set httpOnly and secure flags on dev-tunnel-id cookie
- Add DOMPurify sanitization to Genie chat message markdown rendering

Signed-off-by: Pawel Kosiec <pawel.kosiec@databricks.com>
@pkosiec pkosiec force-pushed the pkosiec/impr-security branch from e217d79 to 6ef9a96 Compare March 25, 2026 18:29
@pkosiec pkosiec changed the title fix: harden cookie flags and sanitize Genie markdown output fix: harden cookie flags, sanitize Genie markdown output, fix remote tunnel Mar 26, 2026
@pkosiec pkosiec marked this pull request as ready for review March 26, 2026 10:38
Signed-off-by: Pawel Kosiec <pawel.kosiec@databricks.com>
@pkosiec pkosiec force-pushed the pkosiec/impr-security branch from a95a2fe to da0912c Compare March 26, 2026 10:51
"build:app": "tsdown --out-dir build server/index.ts && cd client && npm run build",
"build:server": "tsdown --out-dir build server/index.ts",
"install": "cd client && npm ci && cd ..",
"install": "cd client && npm install && cd ..",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

CC @MarioCadenas we need to revert that, otherwise the pnpm deploy:playground doesn't work. The dependencies need to be downloaded on runtime side overriding the local ones (from the npm registry proxy)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

so? npm ci sould work anyway, what's the problem with that?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nope, because the lock file doesn't match - when pnpm deploy:playground runs, the deployed package.json has rewritten dependencies (file: tarballs replaced with registry versions), which means the lockfile no longer matches

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

are we running this one on ci at any moment? or just locally?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

no, only locally

return /^[^./]/.test(id) || id.includes("/node_modules/");
},
tsconfig: "./tsconfig.json",
copy: [
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was needed to resolve an issue that crashed the app when running the tunnel:

node:fs:442
    return binding.readFileUtf8(path, stringToFlags(options.flag));
                   ^

Error: ENOENT: no such file or directory, open '/app/python/source_code/node_modules/@databricks/appkit/dist/plugins/server/remote-tunnel/index.html'
    at Object.readFileSync (node:fs:442:20)
    at file:///app/python/source_code/node_modules/@databricks/appkit/dist/plugins/server/remote-tunnel/remote-tunnel-manager.js:121:18
    at middleware (file:///app/python/source_code/node_modules/@databricks/appkit/dist/plugins/server/remote-tunnel/remote-tunnel-controller.js:60:51) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/app/python/source_code/node_modules/@databricks/appkit/dist/plugins/server/remote-tunnel/index.html'
}

Node.js v22.16.0

prepare-pr-template.ts rewrites dependencies to file: tarballs, which
will never match the lockfile copied from template/ — npm ci will
always fail here, so npm install is required.

Signed-off-by: Pawel Kosiec <pawel.kosiec@databricks.com>
- name: Install template dependencies
working-directory: pr-template
run: npm ci
run: npm install
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

prepare-pr-template.ts rewrites dependencies to file: tarballs, which will never match the lockfile copied from template - so we need to revert this

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

true, but I guess now we have fixed deps it should be fine

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No - see this failure: https://github.com/databricks/appkit/actions/runs/23590462691/job/68694129912
The prepare-pr-template.ts script rewrites deps from registry specifiers to file paths. The lockfile still references the original registry URLs, so npm ci will fail because the specifiers don't match - regardless of whether versions are pinned.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I meant keeping npm install sorry, I understand we can't keep npm ci in there

@pkosiec pkosiec merged commit c39b88b into main Mar 26, 2026
10 checks passed
@pkosiec pkosiec deleted the pkosiec/impr-security branch March 26, 2026 16:42
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.

2 participants