8000 made style sheet imports more flexible by edewit · Pull Request #49647 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Comment on lines +79 to +83
if ("order".equals(id)) {
continue;
}
builders.put(id, ThemeRe 8000 sourceDescriptor.builder(properties.getProperty(key)));
}
Comment on lines +96 to +118
public boolean hasDefer() {
return defer != null && isTruthy(defer);
}

public boolean hasAsync() {
return async != null && isTruthy(async);
}

public boolean hasType() {
return type != null && !type.isEmpty();
}

public boolean hasBlocking() {
return blocking != null && !blocking.isEmpty();
}

public boolean hasRel() {
return rel != null && !rel.isEmpty();
}

private static boolean isTruthy(String value) {
return "true".equalsIgnoreCase(value) || "defer".equalsIgnoreCase(value) || "async".equalsIgnoreCase(value);
}

<#macro renderScripts resources pathPrefix defaultScriptType="">
<#list resources as resource>
<script src="${pathPrefix}/${resource.path}"<#if resource.type?has_content> type="${resource.type}"<#elseif defaultScriptType?has_content> type="${defaultScriptType}"</#if><#if resource.media?has_content> media="${resource.media}"</#if><#if resource.integrity?has_content> integrity="${resource.integrity}"</#if><#if resource.crossorigin?has_content> crossorigin="${resource.crossorigin}"</#if><#if resource.hasDefer> defer</#if><#if resource.hasAsync> async</#if><#if resource.blocking?has_content> blocking="${resource.blocking}"</#if>></script>

<#macro renderScripts resources pathPrefix defaultScriptType="">
<#list resources as resource>
<script src="${pathPrefix}/${resource.path}"<#if resource.type?has_content> type="${resource.type}"<#elseif defaultScriptType?has_content> type="${defaultScriptType}"</#if><#if resource.media?has_content> media="${resource.media}"</#if><#if resource.integrity?has_content> integrity="${resource.integrity}"</#if><#if resource.crossorigin?has_content> crossorigin="${resource.crossorigin}"</#if><#if resource.hasDefer> defer</#if><#if resource.hasAsync> async</#if><#if resource.blocking?has_content> blocking="${resource.blocking}"</#if>></script>

<#macro renderScripts resources pathPrefix defaultScriptType="">
<#list resources as resource>
<script src="${pathPrefix}/${resource.path}"<#if resource.type?has_content> type="${resource.type}"<#elseif defaultScriptType?has_content> type="${defaultScriptType}"</#if><#if resource.media?has_content> media="${resource.media}"</#if><#if resource.integrity?has_content> integrity="${resource.integrity}"</#if><#if resource.crossorigin?has_content> crossorigin="${resource.crossorigin}"</#if><#if resource.hasDefer> defer</#if><#if resource.hasAsync> async</#if><#if resource.blocking?has_content> blocking="${resource.blocking}"</#if>></script>

<#macro renderScripts resources pathPrefix defaultScriptType="">
<#list resources as resource>
<script src="${pathPrefix}/${resource.path}"<#if resource.type?has_content> type="${resource.type}"<#elseif defaultScriptType?has_content> type="${defaultScriptType}"</#if><#if resource.media?has_content> media="${resource.media}"</#if><#if resource.integrity?has_content> integrity="${resource.integrity}"</#if><#if resource.crossorigin?has_content> crossorigin="${resource.crossorigin}"</#if><#if resource.hasDefer> defer</#if><#if resource.hasAsync> async</#if><#if resource.blocking?has_content> blocking="${resource.blocking}"</#if>></script>

<#macro renderScripts resources pathPrefix defaultScriptType="">
<#list resources as resource>
<script src="${pathPrefix}/${resource.path}"<#if resource.type?has_content> type="${resource.type}"<#elseif defaultScriptType?has_content> type="${defaultScriptType}"</#if><#if resource.media?has_content> media="${resource.media}"</#if><#if resource.integrity?has_content> integrity="${resource.integrity}"</#if><#if resource.crossorigin?has_content> crossorigin="${resource.crossorigin}"</#if><#if resource.hasDefer> defer</#if><#if resource.hasAsync> async</#if><#if resource.blocking?has_content> blocking="${resource.blocking}"</#if>></script>
Comment on lines 135 to 138
* styles - Space-separated list of styles to include
* scripts - Space-separated list of scripts to include
* favicons - Space-separated list of favicons to include, or dot-notation entries (see below)
* locales - Comma-separated list of supported locales
10000
Supported attributes:

* styles / stylesCommon: `media`, `integrity`, `crossorigin`
* scripts: `media`, `integrity`, `defer`, `async`, `type`, `crossorigin`, `blocking`
@ssilvert
ssilvert commented Jun 16, 2026 •
Copy link
Copy Markdown
Contributor

Before I let Copilot do its review, I ran a Claude review with Opus. Both found different issues. I'm asking Claude to post inline comments under my user id. We will see how that goes.

ssilvert

This comment was marked as low quality.

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

Adding the findings inline (replaces my earlier hidden summary). The parse → model → render split is clean and the parser tests are thorough; main concern is the macro bug below.


<#macro renderScripts resources pathPrefix defaultScriptType="">
<#list resources as resource>
<script src="${pathPrefix}/${resource.path}"<#if resource.type?has_content> type="${resource.type}"<#elseif defaultScriptType?has_content> type="${defaultScriptType}"</#if><#if resource.media?has_content> media="${resource.media}"</#if><#if resource.integrity?has_content> integrity="${resource.integrity}"</#if><#if resource.crossorigin?has_content> crossorigin="${resource.crossorigin}"</#if><#if resource.hasDefer> defer</#if><#if resource.hasAsync> async</#if><#if resource.blocking?has_content> blocking="${resource.blocking}"</#if>></script>
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.

Likely rendering bug. resource.hasDefer / resource.hasAsync are accessed without parentheses, but hasDefer()/hasAsync() are not JavaBean getters (getX/isX), so FreeMarker's bean wrapper resolves them to the method object, not a boolean — <#if methodModel> raises "Expected a boolean…". Existing templates call no-arg booleans with parens (e.g. auth.showUsername()). A theme that sets scripts.x.defer=true would 500. Use <#if resource.hasDefer()> / resource.hasAsync(), or rename to isDefer()/isAsync(). No test currently renders these macros, so please add one covering a defer/async script. (Same fix needed in all 5 copies of this file.)

@@ -0,0 +1,17 @@
<#macro renderStyles resources pathPrefix>
<#list resources as resource>
<link href="${pathPrefix}/${resource.path}" rel="stylesheet"<#if resource.media?has_content> media="${resource.media}"</#if><#if resource.integrity?has_content> integrity="${resource.integrity}"</#if><#if resource.crossorigin?has_content> crossorigin="${resource.crossorigin}"</#if> />
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.

Unescaped attribute values. Property values are interpolated raw into HTML attributes here (and in renderScripts/renderFavicons below) — e.g. media="${resource.media}". A value containing a double-quote breaks out of the attribute. These are theme-author controlled so severity is limited, but since themes can be uploaded/community-sourced, ${resource.media?html} (or an HTML output format on the macro file) would be good defense-in-depth.

@@ -0,0 +1,17 @@
<#macro renderStyles resources pathPrefix>
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.

Duplication. This macro file is added byte-for-byte in 5 places (base/account, base/admin, base/login community, base/login resources, welcome). Any change — including the hasDefer() fix above — must be made in all five and they will drift. Consider a single shared location via theme inheritance, or at least a comment marking these as synchronized copies.

<title>${title!}</title>
<link rel="icon" href="${url.resourcesPath}/img/favicon.ico" />
<#if properties.stylesCommon?has_content>
<#if themeResources?? && themeResources.favicons?has_content>
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.

Behavior change worth noting. Login previously always rendered a hardcoded img/favicon.ico. Now parseLegacyFavicon populates favicons from the favIcon property (which login historically ignored), and rel becomes icon. So a theme that set favIcon for account now changes login/welcome too. Probably harmless, but please call it out in the PR description.

<#list properties.styles?split(' ') as style>
<link rel="stylesheet" href="${resourceUrl}/${style}">
</#list>
<#if themeResources?? && themeResources.styles?has_content>
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.

Inconsistent fallback. template.ftl guards styles with <#if themeResources??…><#elseif properties.styles?has_content>, but here the <#elseif properties.styles> arm is dropped. It works only because the parser folds legacy styles into themeResources; if themeResources is ever null on this path, styles silently vanish. Worth making the two paths consistent.

continue;
}
String id = matcher.group(2);
if ("order".equals(id)) {
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.

order is effectively a reserved resource id (skipped here), but that isn't documented alongside the "ids must not contain dots" note. A theme using a resource id of order would be silently dropped — worth a doc line.< 10BC8 /p>

&& realm.getAttribute("darkMode", true));
} catch (IOException e) {
e.printStackTrace();
logger.warn("Failed to load theme properties", e);
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.

Nice cleanup — replacing e.printStackTrace() with logger.warn(...) here. 👍

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

@edewit Sorry for the massive AI review. I'm experimenting a bit. Let me know if you found it annoying.

It did raise some good points that should be addressed, but I don't think we have to react to all these.

@edewit
edewit commented Jun 17, 2026
Copy link
Copy Markdown
Contributor Author

@ssilvert addressed the review comments

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
@edewit
edewit force-pushed the style-attributes branch from eaafdf4 to 7d42a7a Compare June 17, 2026 14:32
Copilot AI review requested due to automatic review settings June 17, 2026 14:32
Copilot AI 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.

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 1 comment.

Comment on lines +63 to +70
String flat = properties.getProperty(type);
if (flat != null && !flat.isBlank()) {
for (String path : flat.trim().split("\\s+")) {
if (!path.isEmpty()) {
result.add(buildDescriptor(path, favicon));
}
}
}
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.

Good catch — this is a real inconsistency. The space-separated favicons= list goes through buildDescriptor(path, favicon) with no normalization, while both the dot-notation path and parseLegacyFavicon strip a leading /. With favicons=/favicon.svg, renderFavicons then emits href="${pathPrefix}//favicon.svg".

The suggested patch works. One refinement: all three favicon paths converge on Builder.buildFavicon(), so normalizing the leading slash once there (or via a small normalizeFaviconPath helper) would fix this and remove the two existing inline strips — one place to keep correct instead of three. Worth a quick parser test for the space-separated favicon case too, since none currently covers it.

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.

done

@ssilvert
Copy link
Copy Markdown
Contributor

@edewit Claude was happy with all your fixes. Copilot found one more issue, but Claude thinks Copilot's fix is sub-optimal.

What fun!

See inline comment with Claude's response to Copilot.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
@edewit
edewit commented Jun 19, 2026
Copy link
Copy Markdown
Contributor Author

done

@edewit
edewit requested a review from ssilvert June 19, 2026 13:50
@ssilvert
ssilvert merged commit 76de984 into keycloak:main Jun 22, 2026
88 checks passed
@edewit
edewit deleted the style-attributes branch July 2, 2026 09:01
sashyo pushed a commit to tide-foundation/keycloak-IGA that referenced this pull request Jul 20, 2026
* made style sheet imports more flexible

This extends the way stylesheets are rendered and is backwards
compatible. But now attibutes can be added by using the dot notation.

fixes: keycloak#22042
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>

* PR review fixes

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>

* favIcon path normilize

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>

---------

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
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.

More flexible imports in custom theme (i.e. CSS media queries)

3 participants

0