Skip to content

fix: Update the vault tag id when paste the vault tag - #10402

Open
cwangsmv wants to merge 2 commits into
developfrom
fix/do-not-allow-copying-vault-tag
Open

fix: Update the vault tag id when paste the vault tag#10402
cwangsmv wants to merge 2 commits into
developfrom
fix/do-not-allow-copying-vault-tag

Conversation

@cwangsmv

@cwangsmv cwangsmv commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Background:
Each vault tag has a unique ID that establishes the relationship between the tag and the user-selected vault credential record in the database.

However, when a user copies and pastes a vault tag, the duplicated tags will share the same unique ID. As a result, modifying the credential record linked to one tag can unintentionally affect the other vault as well.

Changes:

  • When paste in editor, add an extra check logic to detect if paste string contains vault tag pattern
  • Generate a new uniqe tag and replace it in the paste content

INS-3535

Copilot AI lite review requested due to automatic review settings August 14, 2026 08:26
@cwangsmv
cwangsmv marked this pull request as draft August 14, 2026 08:26

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

This PR addresses duplicated external vault tag IDs when users copy/paste vault template tags, by regenerating fresh IDs during paste so each pasted tag links to a distinct credential mapping.

Changes:

  • Added external-vault tag ID detection and replacement helpers in templating utilities.
  • Updated CodeMirror-based editors to regenerate vault tag IDs on paste (both single-line and multi-line editors).
  • Refactored legacy vault tag conversion to use the shared ID generator and added unit tests for the replacement logic.

Reviewed changes

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

Show a summary per file
File Description
packages/insomnia/src/ui/components/templating/tag-editor.tsx Switches legacy vault tag conversion to the shared external vault tag ID generator.
packages/insomnia/src/ui/components/.client/codemirror/one-line-editor.tsx Adds paste handling to detect vault tags and regenerate IDs in single-line editor content.
packages/insomnia/src/ui/components/.client/codemirror/code-editor.tsx Adds paste handling to regenerate vault tag IDs (and preserves existing onPaste behavior).
packages/insomnia/src/common/templating/utils.ts Introduces external vault tag ID prefix, generator, detection, and replacement implementation.
packages/insomnia/src/common/templating/tests/utils.test.ts Adds unit tests for vault tag ID replacement behavior.
packages/insomnia/src/common/constants.ts Adds an exported prefix constant for external vault tag IDs.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/insomnia/src/common/templating/utils.ts Outdated
Comment thread packages/insomnia/src/common/constants.ts Outdated
Comment thread packages/insomnia/src/common/templating/utils.ts Outdated

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 5 out of 5 changed files in this pull request and generated no new comments.

Suppressed comments (3)

packages/insomnia/src/ui/components/.client/codemirror/one-line-editor.tsx:218

  • change.text.join('') removes line boundaries before the replace(/\n/g, ' ') runs, so multi-line paste content gets concatenated without spaces (e.g. "a\nb" -> "ab"). Since this is the single-line editor, it should preserve boundaries by joining with newlines (or spaces) before collapsing to a single line.
          let editorPasteText = change.text.join('').replace(/\n/g, ' ');
          if (containsExternalVaultTag(editorPasteText)) {
            editorPasteText = replaceVaultTagIdIfNeeded(editorPasteText);
          }
          // If we're in single-line mode, merge all changed lines into one

packages/insomnia/src/common/templating/utils.ts:180

  • vaultTagIdRegex is exported with the global (g) flag. Global regexes are stateful when used with RegExp.test() (and some matchers), which can lead to flaky behavior across repeated calls. Consider exporting a non-global regex and using a local global clone only where replacement needs it.
const tagRegex = /{%[\s\S]+?%}/g;
export const vaultTagIdRegex = new RegExp(`${externalVaultTagPrefix}_[a-z0-9]{32}`, 'g');
export const containsExternalVaultTag = (input: string) => {

packages/insomnia/src/ui/components/.client/codemirror/one-line-editor.tsx:207

  • isPaste is currently assigned change.origin === 'paste' && change.update, which can evaluate to the update function instead of a boolean. This works at runtime but is confusing for typing and future maintenance; consider making the condition explicitly boolean (or inlining the condition).
      codeMirror.current.on('beforeChange', (_: CodeMirror.Editor, change: CodeMirror.EditorChangeCancellable) => {
        const isPaste = change.origin === 'paste' && change.update;
        if (isPaste) {

@cwangsmv
cwangsmv force-pushed the fix/do-not-allow-copying-vault-tag branch from 77f46f3 to 6cb8d50 Compare August 18, 2026 06:22
@cwangsmv
cwangsmv requested a review from a team August 18, 2026 06:25
@cwangsmv
cwangsmv marked this pull request as ready for review August 18, 2026 06:25
@cwangsmv
cwangsmv force-pushed the fix/do-not-allow-copying-vault-tag branch from 6cb8d50 to f1aa109 Compare August 24, 2026 07:26
@cwangsmv
cwangsmv force-pushed the fix/do-not-allow-copying-vault-tag branch from f1aa109 to dbb5569 Compare August 24, 2026 08:53
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