{"record":{"id":"4ab2f4e3cd2d9cde","repo":"apache/beam","slug":"the-key-s-in-gcs-custom-audit-entries-exceeds-the-d","errorCode":null,"errorMessage":"The key '%s' in GCS custom audit entries exceeds the %d-character limit.","messagePattern":"The key '(.+?)' in GCS custom audit entries exceeds the (.+?)-character limit\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/options/GcsOptions.java","lineNumber":273,"sourceCode":"    private static final int MAX_ENTRIES = 4;\n\n    private static final String CUSTOM_AUDIT_ENTRY_TMPL = \"x-goog-custom-audit-%s\";\n\n    public static final String CUSTOM_AUDIT_JOB_ENTRY_KEY =\n        String.format(CUSTOM_AUDIT_ENTRY_TMPL, \"job\");\n\n    boolean exceedsEntryLimit() {\n      if (this.containsKey(CUSTOM_AUDIT_JOB_ENTRY_KEY)) {\n        return this.size() > MAX_ENTRIES;\n      }\n\n      return this.size() > MAX_ENTRIES - 1;\n    }\n\n    @Override\n    public @Nullable String put(String key, String value) {\n      if (key.length() > MAX_KEY_LENGTH) {\n        throw new IllegalArgumentException(\n            String.format(\n                \"The key '%s' in GCS custom audit entries exceeds the %d-character limit.\",\n                key, MAX_KEY_LENGTH));\n      }\n\n      if (value.length() > MAX_VALUE_LENGTH) {\n        throw new IllegalArgumentException(\n            String.format(\n                \"The value '%s' in GCS custom audit entries exceeds the %d-character limit.\",\n                value, MAX_VALUE_LENGTH));\n      }\n\n      String prefix = CUSTOM_AUDIT_ENTRY_TMPL.substring(0, CUSTOM_AUDIT_ENTRY_TMPL.indexOf('%'));\n      String formattedKey =\n          key.startsWith(prefix) ? key : String.format(CUSTOM_AUDIT_ENTRY_TMPL, key);\n      String oldValue = super.put(formattedKey, value);\n\n      if (exceedsEntryLimit()) {","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/options/GcsOptions.java#L255-L291","documentation":"GcsOptions.GcsCustomAuditEntries is a bounded map of GCS request-header audit entries; put() throws IllegalArgumentException when the key exceeds MAX_KEY_LENGTH (30 chars). Keys are namespaced with the x-goo-custom-audit-job prefix template.","triggerScenarios":"Calling put(key, value) on options.as(GcsOptions.class).getGcsCustomAuditEntries() with a key longer than MAX_KEY_LENGTH, before the prefix is applied.","commonSituations":"Passing long custom audit keys (e.g. full trace IDs or URLs) via pipeline options for header propagation to GCS; test code injecting oversized keys.","solutions":["Shorten the custom audit key to within MAX_KEY_LENGTH (30 characters)","Move long data into the value instead of the key","Hash or truncate the identifier before using it as a key","Check MAX_KEY_LENGTH in GcsOptions and validate user-supplied keys at pipeline-arg parsing time"],"exampleFix":"// before\ngcsOptions.getGcsCustomAuditEntries().put(\"job-namespace-very-long-key-id-12345\", \"v\");\n// after\ngcsOptions.getGcsCustomAuditEntries().put(\"job-key-12345\", \"v\"); // <= 30 chars","handlingStrategy":"validation","validationCode":"void safePut(GcsOptions.GcsCustomAuditEntries entries, String key, String value) {\n  if (key.length() > 30) throw new IllegalArgumentException(\"audit key too long: \" + key);\n  entries.put(key, value);\n}","typeGuard":"boolean validAuditKey(String k) { return k != null && k.length() <= 30; }","tryCatchPattern":"try {\n  entries.put(key, value);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"exceeds the\") && e.getMessage().contains(\"key\")) {\n    key = key.substring(0, 30); entries.put(key, value);\n  } else throw e;\n}","preventionTips":["Keep custom audit keys <= 30 characters","Truncate/hash identifiers before using them as keys","Add a unit test asserting key lengths from user config","Read MAX_KEY_LENGTH from GcsOptions rather than hardcoding"],"tags":["gcp","gcs","validation","limit","java"],"backgroundTag":"value-out-of-range","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}