{"record":{"id":"8136c078ec1f038c","repo":"carrierwaveuploader/carrierwave","slug":"errors-messages-extension-denylist-error","errorCode":null,"errorMessage":"errors.messages.extension_denylist_error","messagePattern":"errors\\.messages\\.extension_denylist_error","errorType":"exception","errorClass":"CarrierWave::IntegrityError","httpStatus":null,"severity":"error","filePath":"lib/carrierwave/uploader/extension_denylist.rb","lineNumber":54,"sourceCode":"\n    private\n\n      def check_extension_denylist!(new_file)\n        denylist = extension_denylist\n        if !denylist && respond_to?(:extension_blacklist) && extension_blacklist\n          CarrierWave.deprecator.warn \"#extension_blacklist is deprecated, use #extension_denylist instead.\" unless instance_variable_defined?(:@extension_blacklist_warned)\n          @extension_blacklist_warned = true\n          denylist = extension_blacklist\n        end\n\n        return unless denylist\n\n        CarrierWave.deprecator.warn \"Use of #extension_denylist is deprecated for the security reason, use #extension_allowlist instead to explicitly state what are safe to accept\" unless instance_variable_defined?(:@extension_denylist_warned)\n        @extension_denylist_warned = true\n\n        extension = new_file.extension.to_s\n        if denylisted_extension?(denylist, extension)\n          raise CarrierWave::IntegrityError, I18n.translate(:\"errors.messages.extension_denylist_error\", extension: new_file.extension.inspect,\n                                                            prohibited_types: Array(extension_denylist).join(\", \"), default: :\"errors.messages.extension_blacklist_error\")\n        end\n      end\n\n      def denylisted_extension?(denylist, extension)\n        Array(denylist).any? { |item| extension =~ /\\A#{item}\\z/i }\n      end\n    end\n  end\nend\n","sourceCodeStart":36,"sourceCodeEnd":65,"githubUrl":"https://github.com/carrierwaveuploader/carrierwave/blob/b5f0abe10ecf6500309fc83e0e8969cf57ba690e/lib/carrierwave/uploader/extension_denylist.rb#L36-L65","documentation":"CarrierWave raises CarrierWave::IntegrityError with this message from the `before :cache` callback `check_extension_denylist!` when the file being cached has an extension that appears in the uploader's `extension_denylist`. The match is anchored (\\A...\\z) and case-insensitive per item. CarrierWave itself warns that denylists are the wrong security tool — using `extension_allowlist` to state what is safe is the recommended pattern, and merely defining `extension_denylist` emits a deprecation warning.","triggerScenarios":"Calling `uploader.cache!(file)` or assigning an uploaded file to a `mount_uploader` attribute when the file's extension equals one of the items in `extension_denylist` (e.g. denylist `%w[exe bat]` and the upload is `setup.exe`). Also triggered via the deprecated `extension_blacklist` fallback when `extension_denylist` is not defined.","commonSituations":"Legacy apps still on `extension_blacklist`/`extension_denylist` after upgrading CarrierWave 2.x (rename plus the security deprecation warning); denylists that block executables but let dangerous web content (`.html`, `.svg` with scripts) through; uploads blocked in staging because the denylist was copied from another app and includes a format the business actually needs (e.g. `pdf`).","solutions":["Replace `extension_denylist` with an explicit `extension_allowlist` of the formats the app actually accepts — this is what CarrierWave recommends and removes the deprecation warning.","If the extension was denied by mistake, remove it from the denylist (or keep it and convert the legitimate use case to another upload path).","Wrap the assignment in `rescue CarrierWave::IntegrityError` and report the message (`extension: ... prohibited_types: ...`) to the user instead of a 500.","Rename the deprecated `extension_blacklist` to `extension_denylist` first if you are mid-migration, then move to the allowlist."],"exampleFix":"# before\nclass DocumentUploader < CarrierWave::Uploader::Base\n  def extension_denylist\n    %w[exe bat sh]\n  end\nend\n# uploading \"invoice.exe\" => CarrierWave::IntegrityError: extension_denylist_error\n\n# after (recommended: explicit allowlist)\nclass DocumentUploader < CarrierWave::Uploader::Base\n  def extension_allowlist\n    %w[pdf doc docx]\n  end\nend","handlingStrategy":"validation","validationCode":"# Deny checks only answer \"is this on the bad list\" — prefer an allowlist at the boundary:\nALLOWED = %w[pdf doc docx].freeze\next = File.extname(uploaded_io.original_filename.to_s).delete_prefix('.').downcase\nreturn false if ext.empty?\nallowed = ALLOWED.any? { |a| ext =~ /\\A#{a}\\z/i }","typeGuard":null,"tryCatchPattern":"begin\n  user.document = params[:document]\nrescue CarrierWave::IntegrityError => e\n  # e.message carries the denylist (prohibited_types) — avoid echoing the raw list to users; substitute your own copy\n  errors.add(:document, :invalid_extension)\nend","preventionTips":["Prefer extension_allowlist over extension_denylist; denylists always miss a dangerous format.","If a denylist is mandatory (policy), review it whenever a new content type becomes uploadable.","Treat a denylist hit as hostile input: log it, don't just show the interpolated message.","Migrate off the deprecated extension_blacklist name so the warning path stays quiet."],"tags":["carrierwave","ruby","file-upload","extension-validation","denylist","security","integrity-error"],"backgroundTag":"file-extension-rejected","analyzedSha":"b5f0abe10ecf6500309fc83e0e8969cf57ba690e","analyzedAt":"2026-08-21T18:07:27.715Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}