Skip to content

codeql: close java/regex-injection alerts #602-#607 (Task 8) - #42

Merged
natechadwick-intsof merged 2 commits into
mainfrom
codeql/regex-injection
Aug 15, 2026
Merged

codeql: close java/regex-injection alerts #602-#607 (Task 8)#42
natechadwick-intsof merged 2 commits into
mainfrom
codeql/regex-injection

Conversation

@natechadwick-intsof

Copy link
Copy Markdown
Collaborator

Summary

Closes 6 CodeQL java/regex-injection High alerts (#602-#607) by treating user-supplied path / site-name components as literals wherever they are composed into regex patterns.

Fixes

Alert File Fix
#603 PSFolderStringUtils.getFolderPatterns Replaced hex-escape loop with Pattern.quote-based literal segment wrapping: split on documented % wildcard, quote each segment, re-join with .*. Compiled regex now carries \\Q...\\E markers CodeQL recognizes. Trailing-/ semantics preserved (decided from raw input, not quoted output).
#604-#606 PSSiteDataService.updateListAsset 3 replaceFirst calls now use Pattern.quote(original) + Matcher.quoteReplacement(replacement)
#607 PSSiteDataService.updatePage replaceFirst(copySiteName, origSiteName) now quoted; same latent pattern at updateLinkedPage fixed identically
#602 PSBlogPostVisitDao.updatePostsAfterSiteRename replaceAll(prevSiteName, newSiteName) now quoted

Why quote

Site/folder names like mysite.com were previously interpreted as regex patterns — . matched any char, (, [, |, + etc. became pattern syntax. Pattern.quote makes them literal; Matcher.quoteReplacement prevents \/$ in replacement strings from being interpreted.

Regression tests

PSFolderStringUtilsTest (JUnit 4):

  • 7 adversarial meta-character inputs (a.b.c, site(name), site$name, site^name, site|name, site[abc]name, site+name) assert literal matching + \\Q marker + no wildcard bleed
  • % wildcard preservation with empty-span match
  • ; multi-path split + null/blank returns empty array
./mvn-env.sh test -pl modules/utils -Dtest=PSFolderStringUtilsTest
# Tests run: 4, Failures: 0, Errors: 0

Verification

./mvn-env.sh compile -pl modules/utils,projects/sitemanage,deliverytiersuite/delivery-tier-suite/metadata -am -DskipTests
# => BUILD SUCCESS

Pattern source

004 branch PR #1295 (ae92a09733) — same CodeQL java/regex-injection rule, same Pattern.quote / Matcher.quoteReplacement idiom; also fixes the equivalent updatePage sink at line 2007 that 004 left untouched.

Notes

  • No Maven dependency change; *.version properties untouched.
  • Per AGENTS.md, Version.properties was not modified.

Close 6 CodeQL High alerts by treating user-supplied path / site-name
components as literals wherever they are composed into regex patterns:

- PSFolderStringUtils.getFolderPatterns (#603): replaced hex-escape
  loop with Pattern.quote-based literal segment wrapping. Path split
  on '%' wildcard, each segment Pattern.quote-wrapped, re-joined with
  '.*' so wildcard still works. Trailing '/' semantics preserved.
- PSSiteDataService.updateListAsset (#604-#606): three replaceFirst
  calls now wrap pattern with Pattern.quote(original) and replacement
  with Matcher.quoteReplacement(replacement).
- PSSiteDataService.updatePage (#607): replaceFirst now uses
  Pattern.quote(copySiteName) + Matcher.quoteReplacement(origSiteName).
  Same latent pattern at updateLinkedPage fixed identically.
- PSBlogPostVisitDao.updatePostsAfterSiteRename (#602): replaceAll
  now uses Pattern.quote(prevSiteName) + Matcher.quoteReplacement.

Regression tests (PSFolderStringUtilsTest):
- 7 adversarial meta-character inputs assert literal matching + \Q
  marker + no wildcard bleed
- % wildcard preservation with empty-span match
- ; multi-path split + null/blank returns empty array

All 4 tests pass. All modules compile.

Fix pattern derived from 004 branch PR #1295 (ae92a09733).

# Please enter the commit message for your changes. Lines starting
# with '#' will be kept; you may remove them yourself if you want to.
# An empty message aborts the commit.
#
# interactive rebase in progress; onto 76f4ae3
# Last command done (1 command done):
#    pick 8f32194 codeql: close java/regex-injection alerts #602-#607 (Task 8)
# No commands remaining.
# You are currently rebasing branch 'codeql/regex-injection' on '76f4ae3e0f'.
#
# Changes to be committed:
#	modified:   CHANGELOG.md
#	modified:   deliverytiersuite/delivery-tier-suite/metadata/src/main/java/com/percussion/delivery/metadata/rdbms/impl/PSBlogPostVisitDao.java
#	modified:   modules/utils/src/main/java/com/percussion/utils/string/PSFolderStringUtils.java
#	modified:   modules/utils/src/test/java/com/percussion/utils/string/PSFolderStringUtilsTest.java
#	modified:   projects/sitemanage/src/main/java/com/percussion/sitemanage/service/impl/PSSiteDataService.java
#
Signed-off-by: Nate Chadwick <natechadwick@users.noreply.github.com>
@natechadwick-intsof
natechadwick-intsof merged commit 8e1dc40 into main Aug 15, 2026
3 checks passed
@natechadwick-intsof
natechadwick-intsof deleted the codeql/regex-injection branch August 15, 2026 00:23
@natechadwick-intsof

Copy link
Copy Markdown
Collaborator Author

Superseded by #50 (consolidated onto current main so the CHANGELOG.md / codeql-config.yml / suppressions.md conflicts no longer block merge). Closing this PR.

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