Git Product home page Git Product logo

Comments (4)

garronej avatar garronej commented on June 27, 2024 4

Thanks a lot for your feedback on this.
It's great to have a solution for the Java side of things.
However I think the best approach would be to have a Keycloakify build option that enable to filter out some path.

Like:

vite.config.ts

export default defineConfig({
  plugins: [
    react(), 
    keycloakify({
      kcContextExcludes: [ 
        "client.attributes.*"
      ]
    })
  ],
})

I'll will work on something.

from keycloakify.

gim- avatar gim- commented on June 27, 2024 2

Thanks for the quick reply @garronej.

I totally agree that most of the information Keycloak adds to FreeMarker context isn't sensitive in a sense that it can't be exploited directly like secrets and private keys, but exposing realm configuration details and client certificate without a need might still raise a huge red flag for security analysts. So, adding a way to directly control what Keycloakify adds to kcContext would be very useful.

But currently, for anyone else who might be concerned about this and stumbles upon this thread - I managed to find a way to get control over what data is added to the FreeMarker context by replacing the default FreeMarkerLoginFormsProvider implementation with a custom one. It's not straightforward nor pretty, but it does solve the problem. Here is a quick example of how it looks like:

public class ReactFreeMarkerLoginFormsProvider extends FreeMarkerLoginFormsProvider {

    public ReactFreeMarkerLoginFormsProvider(KeycloakSession session) {
        super(session);
    }

    @Override
    protected void createCommonAttributes(Theme theme, Locale locale, Properties messagesBundle,
                                          UriBuilder baseUriBuilder, LoginFormsPages page) {
        if (!theme.getName().startsWith("react-")) {
            // Theme name doesn't start with "react-" - proceed with default implementation to not break default theme
            super.createCommonAttributes(theme, locale, messagesBundle, baseUriBuilder, page);
            return;
        }
        // Remove any unused attributes added by parent implementation before this method is called
        attributes.remove("messagesPerField");
        attributes.remove("scripts");
        attributes.remove("properties");

        if (realm != null) {
            URI baseUri = baseUriBuilder.build();
            attributes.put("url", new UrlBean(realm, theme, baseUri, this.actionUri));
            // Any realm related attributes are added here
        }
        if (client != null) {
            // Any client related attributes are added here
        }
    }
}

And to make it work, the default login forms provider needs to be disabled:

kc.sh build --spi-login-freemarker-enabled=false

And Keycloak will automatically find and use the custom FreeMarker forms provider because it's the only one available.

from keycloakify.

garronej avatar garronej commented on June 27, 2024

Hello @gim-,
This is a legitimate preocupation however Keycloak itself, in principle should not expose any sensitive info to the FreeMarker context.

There is currently no way to controle what's exposed but I can do it.
If there are fields that you think thould be removed you can reach me on Discord and I will remove them asap
https://discord.gg/kYFZG7fQmn

from keycloakify.

garronej avatar garronej commented on June 27, 2024

Another approach could also be to perform statitical analisis on the theme source files and to only includes in the client side values that are acutally used.
This requires more work though.

from keycloakify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.