fix(@callstack/licenses): sanitize unsafe characters in AboutLibraries license filenames#169
Merged
mateusz1913 merged 1 commit intoMay 26, 2026
Conversation
…s license filenames License types like `MIT/X11` (e.g. nub@0.0.0, optimist) and compound SPDX expressions like `(MIT OR Apache-2.0)` were used verbatim as part of the filename written under `android/config/licenses/`. The slash caused `writeAboutLibrariesNPMOutput` to fail with ENOENT because the path component before it was treated as a subdirectory; other characters (parens, spaces) produced names that are unsafe on some filesystems. Sanitize anything outside `[A-Za-z0-9._-]` to `_` before using the license type as both the filename prefix and (when content is absent) the sha512 input, so the prefix and hash stay consistent.
Collaborator
|
Hi @alexisloiselle, the changes look good, thanks! Is the PR ready to be undrafted? |
mateusz1913
approved these changes
May 21, 2026
Contributor
Author
Yes! although I'm on my phone right now, will put ready for review whenever I get the chance! |
Contributor
Author
|
@mateusz1913 Undrafted and ready to merge 🎉 |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
prepareAboutLibrariesLicenseFielduseslicense.typeverbatim as part of a filename written underandroid/config/licenses/bywriteAboutLibrariesNPMOutput. When a dependency declares a legacy SPDX expression likeMIT/X11(e.g.nub@0.0.0oroptimist), the unsanitized/causes the writer to attempt to createandroid/config/licenses/MIT/X11_<hash>.json. That fails withENOENTbecauseMIT/is interpreted as a subdirectory that doesn't exist.This PR sanitizes any character outside
[A-Za-z0-9._-]to_before constructing both the filename prefix and the sha512 input (whencontentis absent), so the prefix and hash stay consistent and the filename is always valid.Repro
Without this fix, against
@callstack/licenses@0.3.1:Throws:
After this PR, the same script writes
android/config/licenses/MIT_X11_<hash>.jsonsuccessfully, andlibraryJsonPayload.licenses[0]matcheslicenseJsonPayload.hash.Behaviour change
license.typeMITMIT_<hash>MIT_<hash>(unchanged)Apache-2.0Apache-2.0_<hash>Apache-2.0_<hash>(unchanged)MIT/X11MIT/X11_<hash>(ENOENT on write)MIT_X11_<hash>(MIT OR Apache-2.0)(MIT OR Apache-2.0)_<hash>(unsafe)_MIT_OR_Apache-2.0__<hash>LGPL-2.1-only WITH Classpath-exception-2.0LGPL-2.1-only_WITH_Classpath-exception-2.0_<hash>The allowlist approach (vs. blocklisting just
/()) is chosen because other compound SPDX expressions can also produce filenames that are invalid on some filesystems.Why this matters
Without this fix, any project depending (even transitively) on a package with such a license expression will fail Android license metadata generation entirely (the first throw aborts the loop), or produce an incomplete
android/config/licenses/directory, leading to a missing or broken OSS notice screen.Test plan
packages/licenses-api/src/node/utils/__tests__/packageUtils.test.ts:MITMIT/X11(the reproduction case)(MIT OR Apache-2.0)contentis absent (sanitized type is hashed, matching the prefix)yarn workspace @callstack/licenses test→ 52 passingyarn typescriptyarn lint:jsChecklist
patchbump for@callstack/licenses)