8000 Block *.js.map files in production. by ssilvert · Pull Request #48301 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Block *.js.map files in production. - #48301

Merged
ssilvert merged 4 commits into
keycloak:mainfrom
ssilvert:issue-47545-block-map-files
May 5, 2026
Merged

ssilvert merged 4 commits into
keycloak:mainfrom
ssilvert:issue-47545-block-map-files

Conversation

@ssilvert
@ssilvert ssilvert commented Apr 20, 2026 •
Copy link
Copy Markdown
Contributor

*.js.map files will still be allowed in dev mode for debugging purposes.

Fixes #47545

I tried to find a clean way to write a test for this, but a true test requires running in production mode. This is possible with the existing test infrastructure using --db=dev-file, but no existing test combines start mode with HTTP assertions, making it non-trivial.

An alternative would be adding a config flag to enable blocking in dev mode, similar to --http-accept-non-normalized-paths. However, this tests the flag mechanism rather than the actual production behavior, and I don't want to add a command line argument solely for testability.

*.js.map files will still be allowed in dev mode for debugging purposes.

Fixes keycloak#47545

Signed-off-by: Stan Silvert <ssilvert@redhat.com>
@edewit
edewit commented Apr 21, 2026
Copy link
Copy Markdown
Contributor

Wouldn't it be easier to "just" disable the generation of source maps for a build?

 js/apps/admin-ui/vite.config.ts lines 68-79

      build: {
        ...lib,
        sourcemap: true,
        target: "esnext",
        modulePreload: false,
        cssMinify: "lightningcss",
        manifest: true,
        rollupOptions: {
          input,
          external,
        },
      },

@ssilvert
Copy link
Copy Markdown
Contributor Author

Wouldn't it be easier to "just" disable the generation of source maps for a build?

 js/apps/admin-ui/vite.config.ts lines 68-79

      build: {
        ...lib,
        sourcemap: true,
        target: "esnext",
        modulePreload: false,
        cssMinify: "lightningcss",
        manifest: true,
        rollupOptions: {
          input,
          external,
        },
      },

I don't want to get rid of source maps altogether. They can be useful.

@edewit
edewit commented Apr 21, 2026
Copy link
Copy Markdown
Contributor

The only reason we added them in the first place was so that we could have stack traces in our errors, but most of the time people send us a screenshot of the error page instead. If we don't have them in production we don't need them at all IMO

edewit
edewit previously approved these changes Apr 21, 2026
@edewit edewit 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.

I still think this is stupid, but I'm fine with keeping them for the one in a million, where it could be useful

@ssilvert
Copy link
Copy Markdown
Contributor Author

I do want to say that this PR also protects customers against inadvertently exposing their own map files,

I also think the whole thing is a little stupid as this really doesn't provide much real security but it makes the auditing tools happy.

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

I haven't looked into how these .js.map gets included as static resources or how they are served as I am in a hurry. I just commented on the current code. Whether this is desired solution for #47545 I'll let someone else decide and approve.

void filterSourceMapRequests(BuildProducer<FilterBuildItem> filters, KeycloakRecorder recorder) {
var filter = recorder.getRejectSourceMapFilter();
if (filter != null) {
filters.produce(new FilterBuildItem(filter, SecurityHandlerPriorities.CORS + 1));
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.

In general, IMO you should decide if it is a DEV Mode in a build step, not in the recorder where the byte code is already recorded.

So I suggest to try following:

  • @BuildStep(>
  • drop @Record(ExecutionTime.STATIC_INIT) and KeycloakRecorder recorder and @Consume(ConfigBuildItem.class)
  • use filters.produce(new FilterBuildItem(new RejectSourceMapFilter(), SecurityHandlerPriorities.CORS + 1)), it should work as there is no state and it has (implicit) no arg ctor

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.

@michalvavrik I'm a little out of my element here. Claude Code tells me:
This is a good idea in general Quarkus projects, but it won't work for Keycloak. IsDevelopment.class checks Quarkus's LaunchMode, which is always NORMAL in Keycloak — even when running start-dev. That's exactly why we ended up using Environment.isDevMode() in the recorder rather than LaunchMode.

Does this make sense?

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.

Unfortunately it does. Our start-dev != quarkus dev. At build time we will either be in our dev or prod mode. Much like org.keycloak.quarkus.deployment.IsReAgumentation, you could introduce a IsKeycloakDevMode based upon the Environment call.

@michalvavrik michalvavrik May 1, 2026 •
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.

@ssilvert I didn't know about what @shawkins says, but my suggestion was about keeping it in the build step, I don't care how you detect it in the build step. IMO you can use org.keycloak.quarkus.runtime.Environment#isDevMode inside of the build step or introduce a BooleanSupplier, whatever works for you.

Just to be clear, I am suggesting it because I think it is a better way, practically it makes negligible difference :-) and you don't need to do it.

Signed-off-by: Stan Silvert <ssilvert@redhat.com>
Signed-off-by: Stan Silvert <ssilvert@redhat.com>
@ssilvert
ssilvert requested a review from a team as a code owner May 4, 2026 20:13
Signed-off-by: Stan Silvert <ssilvert@redhat.com>
@shawkins shawkins 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.

LGTM, thanks @ssilvert

@ssilvert
ssilvert merged commit 73c878b into keycloak:main May 5, 2026
93 of 96 checks passed
@stianst stianst mentioned this pull request Jun 1, 2026
@ssilvert
ssilvert deleted the issue-47545-block-map-files branch June 12, 2026 17:54
sashyo pushed a commit to tide-foundation/keycloak-IGA that referenced this pull request Jul 20, 2026
* Block *.js.map files in production.

*.js.map files will still be allowed in dev mode for debugging purposes.

Fixes keycloak#47545

Signed-off-by: Stan Silvert <ssilvert@redhat.com>

* Minor changes from PR review.

Signed-off-by: Stan Silvert <ssilvert@redhat.com>

* Conditionally install the filter at build time.

Signed-off-by: Stan Silvert <ssilvert@redhat.com>

* Restore openapi.yaml, which was changed accidentally.

Signed-off-by: Stan Silvert <ssilvert@redhat.com>

---------

Signed-off-by: Stan Silvert <ssilvert@redhat.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.

Keycloak ships source maps for Admin UI and Account UI

4 participants

0