{"record":{"id":"0b7320315b29e965","repo":"Shopify/liquid","slug":"invalid-base64-provided-to-base64-decode","errorCode":null,"errorMessage":"invalid base64 provided to base64_decode","messagePattern":"invalid base64 provided to base64_decode","errorType":"exception","errorClass":"Liquid::ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/liquid/standardfilters.rb","lineNumber":177,"sourceCode":"    #   Encodes a string to [Base64 format](https://developer.mozilla.org/en-US/docs/Glossary/Base64).\n    # @liquid_syntax string | base64_encode\n    # @liquid_return [string]\n    def base64_encode(input)\n      Base64.strict_encode64(Utils.to_s(input))\n    end\n\n    # @liquid_public_docs\n    # @liquid_type filter\n    # @liquid_category string\n    # @liquid_summary\n    #   Decodes a string in [Base64 format](https://developer.mozilla.org/en-US/docs/Glossary/Base64).\n    # @liquid_syntax string | base64_decode\n    # @liquid_return [string]\n    def base64_decode(input)\n      input = Utils.to_s(input)\n      StandardFilters.try_coerce_encoding(Base64.strict_decode64(input), encoding: input.encoding)\n    rescue ::ArgumentError\n      raise Liquid::ArgumentError, \"invalid base64 provided to base64_decode\"\n    end\n\n    # @liquid_public_docs\n    # @liquid_type filter\n    # @liquid_category string\n    # @liquid_summary\n    #   Encodes a string to URL-safe [Base64 format](https://developer.mozilla.org/en-US/docs/Glossary/Base64).\n    # @liquid_syntax string | base64_url_safe_encode\n    # @liquid_return [string]\n    def base64_url_safe_encode(input)\n      Base64.urlsafe_encode64(Utils.to_s(input))\n    end\n\n    # @liquid_public_docs\n    # @liquid_type filter\n    # @liquid_category string\n    # @liquid_summary\n    #   Decodes a string in URL-safe [Base64 format](https://developer.mozilla.org/en-US/docs/Glossary/Base64).","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/Shopify/liquid/blob/807d45a6b3d4568e64e86b375e3702df2c7c860c/lib/liquid/standardfilters.rb#L159-L195","documentation":"The base64_decode Liquid filter raises Liquid::ArgumentError when Base64.strict_decode64 rejects the input as invalid base64 (wrong characters, incorrect padding, or embedded whitespace/newlines forbidden by strict decoding).","triggerScenarios":"Calling {{ 'not@@base64!' | base64_decode }} with strings containing non-alphabet characters, wrong length (padding), or newlines/spaces that strict_decode64 disallows.","commonSituations":"Base64 strings copied with line breaks from MIME/email bodies; URL-safe base64 (- and _) fed to the strict decoder; truncated or padded-incorrectly strings from external APIs.","solutions":["Validate the input matches ^[A-Za-z0-9+/]*={0,2}$ and has a length multiple of 4 before decoding","Use base64_url_safe_decode if the input uses - and _ characters","Strip whitespace/newlines from the base64 string before decoding"],"exampleFix":"<!-- before -->\n{{ 'aGVsbG8\n' | base64_decode }}\n<!-- after -->\n{{ 'aGVsbG8=' | base64_decode }}","handlingStrategy":"validation","validationCode":"def strict_base64?(s)\n  s.is_a?(String) && s.match?(/\\A[A-Za-z0-9+\\/+]*={0,2}\\z/) && (s.length % 4).zero?\nend","typeGuard":"def standard_base64?(v)\n  v.is_a?(String) && v.match?(/\\A[A-Za-z0-9+\\/]+={0,2}\\z/)\nend","tryCatchPattern":"begin\n  output = Liquid::Template.parse(tpl).render(assigns)\nrescue Liquid::ArgumentError => e\n  raise unless e.message.include?('base64_decode')\n  # fall back to raw input or show placeholder\nend","preventionTips":["Strip newlines/whitespace from base64 before filtering","Use base64_url_safe_decode for -/_ alphabets","Validate base64 at data-ingestion time"],"tags":["liquid","template-engine","base64","encoding","filter"],"backgroundTag":"invalid-base64","analyzedSha":"807d45a6b3d4568e64e86b375e3702df2c7c860c","analyzedAt":"2026-09-08T11:31:38.917Z","contentChangedAt":"2026-09-08T11:31:38.917Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}