Skip to content

Sanitize paths for SSH data#1712

Merged
MarkEWaite merged 1 commit intojenkinsci:stable-6.4from
MarkEWaite:avoid-percent-in-ssh-filename-args
Dec 18, 2025
Merged

Sanitize paths for SSH data#1712
MarkEWaite merged 1 commit intojenkinsci:stable-6.4from
MarkEWaite:avoid-percent-in-ssh-filename-args

Conversation

@MarkEWaite
Copy link
Copy Markdown
Contributor

@MarkEWaite MarkEWaite commented Dec 17, 2025

Sanitize paths for SSH data

SSH has special rules related to '%' characters in its file name arguments. Refer to the ssh_config man page for its descriptions of tokens:

https://man.openbsd.org/ssh_config#TOKENS

If the absolute path to the temporary file for the private key includes a '%' character, then use the system temporary directory instead.

Likewise if the absolute path to the Windows temporary file for the private key includes a ' ', a '(', or a ')', then use the system temporary directory.

Windows

Makes the createTempFile() implementation match the comment.

Fixes #1704

Fixes #1710

Amends 5a271e5

Testing done

  • Confirmed that I can duplicate the bug with a multibranch Pipeline cloned through an SSH URL when one of the branches in the repository contains a '/' character. In my test case, I used 'bug/git-cleint-plugin-1710' as the branch name
  • Confirmed that the bug is resolved by this change

Multibranch Pipeline definition used for test:

pipeline {
    agent {
        label 'windows'
    }
    options {
        skipDefaultCheckout true
    }
    stages {
        stage('Checkout') {
            steps {
                ws('percent%2Fencoded') {
                    checkout scm
                }
                ws('a b') {
                    checkout scm
                }
                ws('c(') {
                    checkout scm
                }
                ws('d)') {
                    checkout scm
                }
                ws('e())') {
                    checkout scm
                }
                ws('f g') {
                    checkout scm
                }
            }
        }
    }
}

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests that demonstrate the feature works or the issue is fixed

SSH has special rules related to '%' characters in its file name
arguments.  Refer to the ssh_config man page for its descriptions
of tokens:

https://man.openbsd.org/ssh_config#TOKENS

If the absolute path to the temporary file for the private key includes a
'%' character, then use the system temporary directory instead.

Likewise if the absolute path to the Windows temporary file for
the private key includes a ' ', a '(', or a ')', then use the system
temporary directory.

Makes the createTempFile() implementation match the comment.

Testing done:

* Confirmed that I can duplicate the bug with a multibranch
  Pipeline cloned through an SSH URL when one of the branches in
  the repository contains a '/' character.  In my test case, I used
  'bug/git-cleint-plugin-1710' as the branch name
* Confirmed that the bug is resolved by this change

Pipeline definition used for test:

pipeline {
    agent {
        label 'windows'
    }
    options {
        skipDefaultCheckout true
    }
    stages {
        stage('Checkout') {
            steps {
                ws('percent%2Fencoded') {
                    checkout scm
                }
                ws('a b') {
                    checkout scm
                }
                ws('c(') {
                    checkout scm
                }
                ws('d)') {
                    checkout scm
                }
                ws('e())') {
                    checkout scm
                }
                ws('f g') {
                    checkout scm
                }
            }
        }
    }
}
@MarkEWaite MarkEWaite added the bug Incorrect or flawed behavior label Dec 17, 2025
@MarkEWaite MarkEWaite requested a review from a team as a code owner December 17, 2025 19:33
@MarkEWaite MarkEWaite added the bug Incorrect or flawed behavior label Dec 17, 2025
@MarkEWaite MarkEWaite changed the title Do not use paths with '%' for SSH data Sanitize paths for SSH data Dec 17, 2025
@MarkEWaite MarkEWaite merged commit 3b5f67d into jenkinsci:stable-6.4 Dec 18, 2025
18 checks passed
@MarkEWaite MarkEWaite deleted the avoid-percent-in-ssh-filename-args branch December 18, 2025 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Incorrect or flawed behavior

Projects

None yet

2 participants