Skip to content

getMimeTypes() race condition results in content getting served as xhtml and failing in safari #15617

@codeconsole

Description

@codeconsole

Expected Behavior

Grails core should not silently fall back to createDefaults() in getMimeTypes() — when there's no request, it should defer caching, not poison it.

org.grails.web.mime.HttpServletResponseExtension.getMimeTypes()

  public static MimeType[] getMimeTypes() {                                                                                           
      if (mimeTypes == null) {                              // ← static field, populated once
          webRequest = GrailsWebRequest.lookup();           // ← thread-local request lookup                                          
          ApplicationContext ctx = webRequest?.getApplicationContext();                                                               
          if (ctx != null) {                                                                                                          
              // CORRECT PATH: read app config via Spring                                                                             
              mimeTypes = ctx.getBean(MimeUtility).getKnownMimeTypes();                                                               
              loadMimeTypeConfig(ctx.getBean(GrailsApplication).config);                                                              
          } else {                                                                                                                    
              // WRONG-FALLBACK PATH:                                                                                                 
              mimeTypes = MimeType.createDefaults();        // [XHTML, HTML, XML, ...]                                                
          }                                                       
      }                                                                                                                               
      return mimeTypes;                                           
  } 

Actual Behaviour

No response

Steps To Reproduce

No response

Environment Information

No response

Example Application

No response

Version

7.0.10

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Bug.

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions