Skip to content

[JENKINS-59849] Don't fail to serve resource files with nontrivial names - #4302

Merged
daniel-beck merged 2 commits into
jenkinsci:masterfrom
daniel-beck:JENKINS-59849
Oct 19, 2019
Merged

[JENKINS-59849] Don't fail to serve resource files with nontrivial names#4302
daniel-beck merged 2 commits into
jenkinsci:masterfrom
daniel-beck:JENKINS-59849

Conversation

@daniel-beck

Copy link
Copy Markdown
Member

See JENKINS-59849.

Proposed changelog entries

  • Bug: Resource URLs failed to serve files with nontrivial names due to encoding problems.

Submitter checklist

  • JIRA issue is well described
  • Changelog entry appropriate for the audience affected by the change (users or developer, depending on the change). Examples
    * Use the Internal: prefix if the change has no user-visible impact (API, test frameworks, etc.)
  • Appropriate autotests or explanation to why this change has no tests
  • [n/a] For dependency updates: links to external changelogs and, if possible, full diffs

@daniel-beck daniel-beck added the bug For changelog: Minor bug. Will be listed after features label Oct 18, 2019
}

private static Token decode(String value) {
byte[] byteValue = Base64.getUrlDecoder().decode(value);

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.

Not strictly related, but @jsoref could make this throw an exception, so just move it down.

@jglick

jglick commented Oct 18, 2019

Copy link
Copy Markdown
Member

amending #4239

Comment thread core/src/main/java/jenkins/security/ResourceDomainRootAction.java
restOfPath = "/" + restOfPath;
}
return resourceRootUrl + getUrlName() + "/" + token.encode() + restOfPath;
return resourceRootUrl + getUrlName() + "/" + token.encode() + Arrays.stream(restOfPath.split("[/]")).map(Util::rawEncode).collect(Collectors.joining("/"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is going to drop a trailing / so that is no good. It will also convert "/" to "".

@daniel-beck daniel-beck Oct 18, 2019

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.

Added a test that hopefully demonstrates that this does not matter.

Redirect URLs are only ever obtained for files, and directory browsing on the resource domain continues to work.

Comment thread core/src/main/java/jenkins/security/ResourceDomainRootAction.java
@jsoref

jsoref commented Oct 18, 2019

Copy link
Copy Markdown
Contributor

Fwiw, I tested this PR using:

node('master') {
   sh '''A='a/'"$(perl -e 'for ($a=1; $a < 50; $a++) { next if $a >= 10 && $a <= 13; next if $a == 8 || $a == 47; print "$a ".chr($a)." "}')"
   mkdir -p "$A"
   echo "hello" > "$A/index.html"
   '''
   archiveArtifacts 'a/'
}

And it worked... including browsing directories...

@daniel-beck
daniel-beck requested a review from jglick October 18, 2019 20:15

@jglick jglick left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK if it works I guess.

public Token getToken(@Nonnull DirectoryBrowserSupport dbs, @Nonnull StaplerRequest req) {
// This is the "restOfPath" of the DirectoryBrowserSupport, i.e. the directory/file/pattern "inside" the DBS.
final String dbsFile = req.getRestOfPath();
final String dbsFile = req.getOriginalRestOfPath();

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 is the most important part of the fix, otherwise the math below will be off: We subtracted the length of foo bar from a string ending in whatever/foo%20bar

@jeffret-b jeffret-b 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.

Looks like it should do the job. I've read through the code but haven't done any additional testing.

@jvz jvz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Changes look reasonable to me.

@daniel-beck

Copy link
Copy Markdown
Member Author

Manually tested with 𐎘 from #4152 in job name (and URL) as well as file name.

Screenshot 2019-10-19 at 00 35 00

http://127.0.0.1:8080/jenkins/static-files/7rlVbi91B5cBBazQTJbJrwPoXTA9GfgQmNgreolJ2vFhZG1pbjoxNTcxNDM4MDA4MzQ3OmpvYi8lRjAlOTAlOEUlOTgvd3M=/%F0%90%8E%98.html

Screenshot

@daniel-beck
daniel-beck merged commit 3de4d8f into jenkinsci:master Oct 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug For changelog: Minor bug. Will be listed after features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants