Repository navigation
OpenConceptLab/ocl_issues#2888 | An organization's banner can be uploaded and removed - #1129
Conversation
…ited by the orgs.banner_file_size_kb capability
…point, has one size limit, and gets a new file name - POST /orgs/:org/banner/ asks the policy about `set_banner` before it stores anything, as a change of overview.background.image does. Removing a banner isn't asked about. - One limit of 2 MB for every image replaces the orgs.banner_file_size_kb capability. - Each upload is stored under its own name, so browsers don't show the image it replaces. The name sent with the image isn't used. - Data that isn't a PNG, JPEG or GIF, whatever type it says it is, is a 400. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWierCikGzbXQj3GN3
…tever JSON the overview and the request hold - A body that isn't an object is a 400. - An overview, or its background, that isn't an object no longer fails an upload, and removing a banner that isn't there changes nothing. - A replaced file that can't be deleted no longer fails the request: the organization has its new banner by then. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWierCikGzbXQj3GN3
… deleted never fails the request, whichever storage is used Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWierCikGzbXQj3GN3
…e is down Deleting its file is best effort from the start: connecting to storage can fail too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWierCikGzbXQj3GN3
… an upload's is deleted with its banner Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWierCikGzbXQj3GN3
Codex review, pass 1 (codex-cli 0.171.0, commit 2d7ebde)Verdict: 6 findings, 3 of them P0 or P1.
findings.json{
"reviewer": "codex-cli 0.171.0",
"perspective": "defects",
"mode": "full",
"commit": "2d7ebde3",
"verdict": "findings",
"prior": [],
"findings": [
{
"id": "F1.1",
"severity": "P1",
"tag": null,
"file": "core/orgs/views.py",
"line": 147,
"claim": "A top-level JSON array or scalar returns 500 instead of 400.",
"scenario": "An authorized admin with a permitting policy posts `[]` as JSON. The parser returns a list, and `request.data.get('base64')` raises `AttributeError` before validation.",
"action": "Validate that the parsed body is an object before reading `base64`. Add a request-level test for a top-level array and scalar.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F1.2",
"severity": "P1",
"tag": null,
"file": "core/orgs/models.py",
"line": 79,
"claim": "The upload accepts and stores truncated files that contain an image signature but cannot render.",
"scenario": "A PNG data URL containing only the eight-byte PNG signature passes validation, replaces the current banner, and returns 200. The positive PNG integration test uses exactly this payload, so it never verifies a usable image.",
"action": "Verify that the decoded bytes form a complete image of the declared type before storage. Use valid PNG, JPEG, and GIF fixtures and assert that signature-only payloads return 400 without storing anything.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F1.3",
"severity": "P1",
"tag": null,
"file": "core/orgs/models.py",
"line": 103,
"claim": "The storage URL prefix is the only ownership check before deleting an object.",
"scenario": "An admin sets the overview image to an existing, manually managed object under the organization's banner folder. Replacing or removing the banner deletes that object even though the upload endpoint never stored it. The deletion test expects removal of `old.png`, a name this endpoint cannot generate.",
"action": "Track uploaded object keys against the organization record and delete only keys with verified ownership. Test that replacement and removal leave an untracked object under the same prefix intact.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F1.4",
"severity": "P2",
"tag": null,
"file": "core/orgs/models.py",
"line": 110,
"claim": "The banner endpoint assumes existing overview values are objects and can also rewrite the overview when there is no image to remove.",
"scenario": "The existing overview API accepts `{\"background\":\"blue\"}`. A subsequent banner upload stores the file and then returns 500 when `dict('blue')` raises. Deleting a banner from the already-supported overview `{\"background\":null}` silently changes it to `{}` even though it had no image.",
"action": "Handle existing JSON shapes explicitly before uploading. Make deletion a no-op when no image exists and preserve unrelated overview values.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F1.5",
"severity": "P2",
"tag": null,
"file": "core/orgs/models.py",
"line": 94,
"claim": "A concurrent About edit can restore a banner URL after its file has been deleted.",
"scenario": "An About edit loads the organization while banner A is current. A concurrent upload saves banner B and deletes A. The About edit then saves its stale organization instance, writing the old overview back along with the new text. The organization now points to deleted banner A.",
"action": "Limit organization detail updates to the fields they own so an About edit cannot overwrite the overview. Cover the interleaving in a concurrency test.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F1.6",
"severity": "P2",
"tag": null,
"file": "core/orgs/models.py",
"line": 97,
"claim": "A failed storage deletion leaves a public banner file that retrying DELETE cannot remove.",
"scenario": "The organization update commits, then S3 returns a transient error during object deletion. The request returns 500. On retry, the overview no longer holds the old key, so the endpoint returns 204 while the file remains public.",
"action": "Persist the verified key for retryable cleanup as part of the overview update and test recovery after a storage deletion failure.",
"lines_delta": null,
"confidence": "high"
}
]
} |
|
Answers to pass 1 (fixes in e41ac8d)
|
Codex review, pass 2 (codex-cli 0.171.0, commit e41ac8d)Verdict: 3 findings, 1 of them P0 or P1.
findings.json{
"reviewer": "codex-cli 0.171.0",
"perspective": "defects",
"mode": "verify",
"commit": "e41ac8df",
"verdict": "findings",
"prior": [
{
"id": "F1.1",
"status": "resolved"
},
{
"id": "F1.2",
"status": "unresolved"
},
{
"id": "F1.3",
"status": "unresolved"
},
{
"id": "F1.4",
"status": "resolved"
},
{
"id": "F1.5",
"status": "unresolved"
},
{
"id": "F1.6",
"status": "unresolved"
}
],
"findings": [
{
"id": "F2.1",
"severity": "P1",
"tag": null,
"file": "core/orgs/models.py",
"line": 109,
"claim": "MinIO cleanup errors still turn a saved banner change into an HTTP 500.",
"scenario": "An admin removes or replaces an uploaded banner and MinIO returns a deletion error for the old object. The overview change has already been saved when MinIO raises, so the client sees a failure even though the banner was cleared or replaced.",
"action": "Handle storage cleanup errors after the overview save and add a test that checks the successful response when MinIO raises.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F2.2",
"severity": "P2",
"tag": null,
"file": "core/orgs/models.py",
"line": 88,
"claim": "Reusing an organization mnemonic lets the new organization delete the former organization's banner.",
"scenario": "An organization uploads a banner and is purged, leaving its object in storage. A new organization registers the same mnemonic and sets its overview image to that old public URL. Removing or replacing the image deletes the former organization's file because both organizations share the same storage prefix.",
"action": "Scope banner keys and deletion checks to the immutable organization ID, and test mnemonic reuse.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F2.3",
"severity": "P2",
"tag": null,
"file": "core/orgs/models.py",
"line": 76,
"claim": "Malformed Base64 data URLs can return 200.",
"scenario": "An admin submits a PNG data URL with an exclamation mark inserted into its Base64 payload. Validation and storage both discard the illegal character, so the endpoint uploads the file and returns 200 instead of rejecting the malformed data URL with 400.",
"action": "Reject characters outside the Base64 alphabet during validation and add a test with an illegal character embedded in an otherwise valid image payload.",
"lines_delta": null,
"confidence": "high"
}
]
} |
|
Answers to pass 2 (fixes in a2d4d25)
|
Codex review, pass 3 (codex-cli 0.171.0, commit a2d4d25)Verdict: 2 findings, 2 of them P0 or P1.
findings.json{
"reviewer": "codex-cli 0.171.0",
"perspective": "defects",
"mode": "verify",
"commit": "a2d4d250",
"verdict": "findings",
"prior": [
{
"id": "F1.1",
"status": "resolved"
},
{
"id": "F1.2",
"status": "unresolved"
},
{
"id": "F1.3",
"status": "unresolved"
},
{
"id": "F1.4",
"status": "resolved"
},
{
"id": "F1.5",
"status": "unresolved"
},
{
"id": "F1.6",
"status": "unresolved"
},
{
"id": "F2.1",
"status": "unresolved"
},
{
"id": "F2.2",
"status": "unresolved"
},
{
"id": "F2.3",
"status": "unresolved"
}
],
"findings": [
{
"id": "F3.1",
"severity": "P1",
"tag": null,
"file": "core/orgs/models.py",
"line": 107,
"claim": "Banner deletion can still return 500 after the overview update commits.",
"scenario": "An admin deletes a banner while MinIO is temporarily unreachable. The API clears the image in the database, then initializes a storage client. MinIO checks the bucket during initialization, and that call can fail before the cleanup exception handler runs. The admin gets a 500 even though the banner was cleared. Deleting when there is no banner can also return 500.",
"action": "Skip storage initialization when there is no prior image URL. Put client initialization and object removal inside the best-effort cleanup handler, and test a failure during client initialization.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F3.2",
"severity": "P1",
"tag": null,
"file": null,
"line": null,
"claim": "About existing code that this change does not touch. It is handled separately.",
"scenario": null,
"action": null,
"lines_delta": null,
"confidence": "high"
}
]
} |
|
Answers to pass 3 (fixes in c82b06d)
|
Simplification review (a fresh Claude subagent, commit c82b06d)Four suggestions, none taken:
Access review (a fresh Claude subagent, commit c82b06d)It tried to upload or remove a banner without being an admin or staff, to get a banner past the write checkpoint, to store something other than a PNG, JPEG or GIF, and to have a file deleted that isn't the organization's banner.
|
…e image is decoded Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWierCikGzbXQj3GN3
Codex check of commits 3f5f4d5..f435f62 (codex-cli 0.171.0)Verdict: 1 finding, 0 of them P0 or P1.
findings.json{
"reviewer": "codex-cli 0.171.0",
"perspective": "defects",
"mode": "final",
"commit": "f435f625",
"verdict": "findings",
"prior": [],
"findings": [
{
"id": "FC.1",
"severity": "P2",
"tag": null,
"file": "core/orgs/models.py",
"line": 83,
"claim": "The new size check rejects a valid banner at the limit when its base64 contains spaces the decoder ignores.",
"scenario": "Upload a valid 2 MiB PNG with two ASCII spaces inside its base64 text. The previous validator accepted it because it decodes to 2,097,152 bytes. The new estimate is 2,097,153 bytes, so the endpoint returns HTTP 400.",
"action": "Exclude spaces and tabs from the pre-decode size calculation, continue counting line breaks, and add a boundary test for base64 containing spaces.",
"lines_delta": null,
"confidence": "high"
}
]
}Answer. f435f62 decides a banner's size from the length of the base64 text, before it's decoded.
All tests pass on f435f62: 4,304 without Elasticsearch and 815 with it. |
snyaggarwal
left a comment
There was a problem hiding this comment.
Approve. Merge order, as Jon gave it on OpenConceptLab/ocl_online#354: OpenConceptLab/ocl_online_api#130, then #1116, then this. Its base is #1116's branch. #1116 has its own condition before merging (see my comment there), and this waits for that too.
POSTasksset_bannerabout the organization as stored, before validating or storing anything. Every upload gets a new file name, so every upload is "a banner other than the one it has", which matchesgets_banner()and the contract #130 answers. #130's notice reads the stored overview to choose its wording, and that's still what it receives.DELETEisn't asked about, the same as removing the banner through the overview. So "remove but not replace" still holds after the policy starts refusing.- A refused upload stores nothing (tested with the upload mocked). A member who isn't an admin gets the usual 403 without the policy being asked (tested for the upload too).
Other checks
- Open core: the 2 MB limit is the same for everyone and protects the server. Replacing the per-owner
orgs.banner_file_size_kbcapability keeps plan-shaped limits out of this code. Constants and messages are neutral. - Size before decoding: the decoded size is worked out from the base64 length before
b64decode, well underDATA_UPLOAD_MAX_MEMORY_SIZE. - Deletion: a file is deleted only if the stored address is exactly
public_url_for(<this org's banner folder> + <32 hex>.<ext>). An admin who saves another organization's file address, or a logo's, can't get it deleted. Storage failures are logged, not 500s. - Concurrent writes:
set_banner_imagelocks the row and rebuildsoverviewfrom it, so the rest of the overview and the About text stay as they are. - Edge cases: a body that isn't an object, a type that isn't PNG, JPEG or GIF, content whose bytes don't match its declared type, and an
overvieworbackgroundthat isn't an object all have tests.
Already raised in Jon's review passes, and I agree with the answers:
- F1.2: a truncated image passes the type check.
- F1.5: overlapping About and upload saves.
- F2.2: a reused mnemonic.
- F2.3 and FC.1: base64 whitespace.
No new findings.
Adds
POSTandDELETE /orgs/:org/banner/, the API half of OpenConceptLab/ocl_issues#2888: an organization's admins can upload the banner that its Overview page shows, instead of hosting the image somewhere else. The first commit is @snyaggarwal's endpoint, as he wrote it. The commits after it are what changed since.It goes on top of #1116, so this PR's base is that branch. Please merge #1116 first.
What it does
POST {"base64": "<data URL>"}stores a PNG, JPEG or GIF of at most 2 MB, setsoverview.background.imageto its address and returns the overview. The rest ofoverviewand the About text stay as they are.DELETEremoves the banner.What changed since the first commit
set_bannerbefore anything is stored, asPUT /orgs/:org/overview/does. A refusal is a 403 with the policy's body. Removing a banner isn't asked about. The default policy allows everything.orgs.banner_file_size_kbcapability. An image that's too large is a 400 that says so, decided before it's decoded.namein the request isn't used.Tests
pylint -j0 core/exits 0.Deploying
No migration and no setting. The capability was never in a release, so there's nothing to remove.
🤖 Generated with Claude Code
https://claude.ai/code/session_01AaZ4qWierCikGzbXQj3GN3