8000 Disable FreeMarker ?new() built-in in themes. by gaoyikeshuer · Pull Request #48280 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Disable FreeMarker ?new() built-in in themes. - #48280

Merged
stianst merged 1 commit into
keycloak:mainfrom
gaoyikeshuer:47915-fix-issue
Apr 21, 2026
Merged

stianst merged 1 commit into
keycloak:mainfrom
gaoyikeshuer:47915-fix-issue

Conversation

@gaoyikeshuer
Copy link
Copy Markdown
Contributor

Closes #47915

@gaoyikeshuer
gaoyikeshuer requested a review from a team as a code owner April 20, 2026 14:46
@gaoyikeshuer
gaoyikeshuer marked this pull request as draft April 20, 2026 14:52
@gaoyikeshuer
gaoyikeshuer commented Apr 21, 2026 •
Copy link
Copy Markdown
Contributor Author

created a login ftl page to test if the fix is working or not.

`

<title>47915 PoC</title>

FreeMarker ?new() PoC

1. Arbitrary class instantiation

<#attempt> <#assign sb = "java.lang.StringBuilder"?new()> ${sb.append("hello-from-").append("?new()").toString()} <#recover> INSTANTIATION FAILED: ${.error}

2. OS command execution via freemarker.template.utility.Execute

<#attempt> <#assign ex = "freemarker.template.utility.Execute"?new()>
id       -> ${ex("id")}
whoami   -> ${ex("whoami")}
uname -a -> ${ex("uname -a")}
<#recover> EXECUTE FAILED: ${.error}

If you see shell output above, the bug reproduces.

`

before fix:
image

After fix:
image

@gaoyikeshuer
gaoyikeshuer marked this pull request as ready for review April 21, 2026 09:50
@rmartinc rmartinc 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.

Thanks @gaoyikeshuer! Looks good! Please just change the warning to use the typical warning the docs/guides are using in other places. With that it's OK to me.

I also thought about adding a note in the upgrading guide (notable change). But I think that it's OK like it is. If someone thinks different please comment it to @gaoyikeshuer.

@mabartos
Copy link
Copy Markdown
Member

@gaoyikeshuer LGTM, just update the warning as @rmartinc and I think it's ready to go.

Signed-off-by: Yike Gao <yikegao8@gmail.com>
@mabartos mabartos 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.

LGTM, thanks!

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

Thanks @gaoyikeshuer! LGTM too!

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.federation.ldap.LDAPSearchForUsersPaginationTest#testPagination

Keycloak CI - Base IT (5)

java.lang.AssertionError: 

Expected: a collection with size <10>
     but: collection size was <2>
	at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
...

Report flaky test

@keycloak-github-bot keycloak-github-bot Bot 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.

Unreported flaky test detected, please review

@mabartos
Copy link
Copy Markdown
Member

@rmartinc @gaoyikeshuer I believe it should be backported.

@stianst
stianst merged commit fa58c07 into keycloak:main Apr 21, 2026
85 checks passed
Sivakajan-tech pushed a commit to Sivakajan-tech/keycloak that referenced this pull request Apr 21, 2026
…eycloak#48280)

Signed-off-by: Yike Gao <yikegao8@gmail.com>
Signed-off-by: sivakajan1 <sivakajan@zerobeta.xyz>
@gaoyikeshuer
gaoyikeshuer deleted the 47915-fix-issue branch April 24, 2026 09:54
@stianst stianst mentioned this pull request Jun 1, 2026
sashyo pushed a commit to tide-foundation/keycloak-IGA that referenced this pull request Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FreeMarker templates allow instantiation of new objects and even running OS commands

4 participants

0