Skip to content

Reject relative package URIs#1683

Merged
stackoverflow merged 3 commits into
apple:mainfrom
stackoverflow:relative-package-uris
Jun 17, 2026
Merged

Reject relative package URIs#1683
stackoverflow merged 3 commits into
apple:mainfrom
stackoverflow:relative-package-uris

Conversation

@stackoverflow

Copy link
Copy Markdown
Contributor

No description provided.

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

Some nits, but also: can you add a test in pkl-core/src/test/files/LanguageSnippetTests/input/packages?

var resolved = cacheDir.resolve(relativePath).normalize();
if (!resolved.startsWith(cacheDir.normalize())) {
throw new SecurityException(
ErrorMessages.create("packageUriEscapesCacheDir", uri.getUri()));

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.

Can this ever happen? It's not possible to construct a PackageUri with path traversal segments now, right?

If not, we can just change this to:

assert resolved.startsWith(cacheDir.normalize());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, this shouldn't happen. But it's a second line of defense, so I think it's worth leaving it there.

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.

Gotcha, makes sense. I think, in this case, we should turn this into a PklBugException, because this is a bug on our part.

Comment thread pkl-core/src/main/resources/org/pkl/core/errorMessages.properties Outdated
@stackoverflow stackoverflow merged commit bfac0d6 into apple:main Jun 17, 2026
22 checks passed
@stackoverflow stackoverflow deleted the relative-package-uris branch June 17, 2026 13:39
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