Skip to content

feat: safely expand Confluence /x/<key> shortened links - #19

Merged
takeoverjp merged 2 commits into
Toyota:mainfrom
trickstar0301:worktree-shorten-url
Aug 23, 2026
Merged

feat: safely expand Confluence /x/<key> shortened links#19
takeoverjp merged 2 commits into
Toyota:mainfrom
trickstar0301:worktree-shorten-url

Conversation

@trickstar0301

Copy link
Copy Markdown
Contributor

Summary

  • Add is_confluence_short_url / expand_confluence_short_url to confluence.rs to resolve Confluence's shortened /x/<key> links (including Cloud's /wiki/x/<key> format) before page-ID resolution.
  • Redirects are never auto-followed: the Location header is only trusted after validating it is HTTPS, carries no userinfo, and is same-origin (host + port) with the short URL. The short URL itself must also be HTTPS, checked before any request is sent so the access token is never transmitted in cleartext.
  • Fix a pre-existing stale hardcoded User-Agent version string (now derived from CARGO_PKG_VERSION).
  • Update README.md and ARCHITECTURE.md to document the new short-link support and validation rules.

Test plan

  • mise run ci (fmt, clippy -D warnings, build, cargo test --all-targets, cargo machete) passes locally
  • Added Wiremock-based tests covering: HTTPS/userinfo/same-origin rejection, non-redirect responses, relative Location resolution, and Confluence Cloud short-link path detection

…ct chain

resolve_page_id_from_url now transparently resolves Confluence's /x/<key>
shortened links (including Cloud's /wiki/x/<key> format) and the
tinyurl.action?urlIdentifier=... hop they redirect through, before
falling back to the existing pageId/spaces/display/spaceKey+title
patterns.

Redirects are never auto-followed; each hop's Location is validated
(HTTPS, no userinfo, same origin) before being trusted, bounded by
MAX_REDIRECT_HOPS to prevent an unbounded chain. The initial URL must
itself be HTTPS, checked before any request is sent so the access
token is never transmitted in cleartext.

@takeoverjp takeoverjp 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.

@trickstar0301
Thank you very much for your first contribution to confluence2md! 🎉
This is a very valuable feature, and I learned a lot from reviewing your PR 😍
I've suggested very slight modification 📝
Could you please check it?

Comment thread src/confluence.rs
Comment thread src/confluence.rs
Comment thread src/confluence.rs
Co-authored-by: Kondo Takeo <takeoverjp@gmail.com>

@takeoverjp takeoverjp 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.

Thank you!
LGTM 👍
I'll release it soon!

@takeoverjp
takeoverjp merged commit 5c2e972 into Toyota:main Aug 23, 2026
1 check passed
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