{"record":{"id":"0e7fdc4d42f29c11","repo":"Shopify/liquid","slug":"invalid-base64-provided-to-base64-url-safe-decode","errorCode":null,"errorMessage":"invalid base64 provided to base64_url_safe_decode","messagePattern":"invalid base64 provided to base64_url_safe_decode","errorType":"exception","errorClass":"Liquid::ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/liquid/standardfilters.rb","lineNumber":202,"sourceCode":"    #   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).\n    # @liquid_syntax string | base64_url_safe_decode\n    # @liquid_return [string]\n    def base64_url_safe_decode(input)\n      input = Utils.to_s(input)\n      StandardFilters.try_coerce_encoding(Base64.urlsafe_decode64(input), encoding: input.encoding)\n    rescue ::ArgumentError\n      raise Liquid::ArgumentError, \"invalid base64 provided to base64_url_safe_decode\"\n    end\n\n    # @liquid_public_docs\n    # @liquid_type filter\n    # @liquid_category string\n    # @liquid_summary\n    #   Returns a substring or series of array items, starting at a given 0-based index.\n    # @liquid_description\n    #   By default, the substring has a length of one character, and the array series has one array item. However, you can\n    #   provide a second parameter to specify the number of characters or array items.\n    # @liquid_syntax string | slice\n    # @liquid_return [string]\n    def slice(input, offset, length = nil)\n      offset = Utils.to_integer(offset)\n      length = length ? Utils.to_integer(length) : 1\n\n      begin\n        if input.is_a?(Array)","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/Shopify/liquid/blob/807d45a6b3d4568e64e86b375e3702df2c7c860c/lib/liquid/standardfilters.rb#L184-L220","documentation":"The base64_url_safe_decode Liquid filter raises Liquid::ArgumentError when Base64.urlsafe_decode64 cannot decode the input — typically because it contains standard-alphabet characters (+ and /) or is malformed (bad padding/length).","triggerScenarios":"Calling {{ 'a+b/c==' | base64_url_safe_decode }} with standard base64 containing + or /, or a string with invalid length/padding for URL-safe decoding.","commonSituations":"Feeding standard base64 (from JWT segments or API responses using + /) into the URL-safe filter; truncated tokens; padding mixed with URL-safe unpadded encoding.","solutions":["Use base64_decode for standard base64 strings containing + or /","Ensure the input uses - and _ alphabet characters with correct padding","Validate the string length and alphabet before decoding"],"exampleFix":"<!-- before -->\n{{ 'a+b/c==' | base64_url_safe_decode }}\n<!-- after -->\n{{ 'a-b_c==' | base64_url_safe_decode }}","handlingStrategy":"validation","validationCode":"def urlsafe_base64?(s)\n  s.is_a?(String) && s.match?(/\\A[A-Za-z0-9_-]*={0,2}\\z/) && (s.length % 4).zero?\nend","typeGuard":"def urlsafe_alphabet?(v)\n  v.is_a?(String) && !v.match?(/[+\\/]/)\nend","tryCatchPattern":"begin\n  output = Liquid::Template.parse(tpl).render(assigns)\nrescue Liquid::ArgumentError => e\n  raise unless e.message.include?('base64_url_safe_decode')\n  # retry with base64_decode for standard alphabet input\nend","preventionTips":["Match the filter to the base64 alphabet used by the producer","Validate alphabet/padding before filtering","Test with tokens from real API payloads"],"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"}