You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to check the existence of a file within a private storage bucket, if the RLS policy fails, a storage error of type StorageUknownError with HTTP status 400 is returned from the JavaScript client.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
Create a private bucket with a simple failing RLS policy.
-- Create the bucket for assets
insert into storage.buckets(id, name, public)
values ('assets', 'assets', false);
-- Create a policy that will always fail
-- NOTE: Changing false to true here results in a successful response
create policy "Users can never access" on storage.objects
for select to public using (bucket_id = 'assets' and false);
Apply the migration
Seed it with an asset (optional)
Try to access the bucket by checking the existence of such an asset. For example...
import { createClient } from "@supabase/supabase-js";
const main = async () => {
// Check for URL, anon key and service role key
if (!process.env.SUPABASE_URL) {
console.error("No SUPABASE_URL environment variable found. Exiting...");
process.exit(1);
}
if (!process.env.SUPABASE_SERVICE_ROLE_KEY) {
console.error(
"No SUPABASE_SERVICE_ROLE_KEY environment variable found. Exiting...",
);
process.exit(1);
}
if (!process.env.SUPABASE_ANON_KEY) {
console.error(
"No SUPABASE_ANON_KEY environment variable found. Exiting...",
);
process.exit(1);
}
const serviceClient = createClient(
process.env.SUPABASE_URL,
process.env.SUPABASE_SERVICE_ROLE_KEY,
);
// Create a user
const DEFAULT_PASSWORD = "Developer123!";
const adminUserResponse = await serviceClient.auth.admin.createUser({
email: "hello@example.com",
password: DEFAULT_PASSWORD,
email_confirm: true,
user_metadata: {
first_name: "Bill",
last_name: "Keys",
},
});
if (!adminUserResponse?.data.user) {
console.error(
"No user returned from Supabase signup. Error:",
adminUserResponse.error,
);
console.log("Exiting...");
process.exit(1);
}
const client = createClient(
process.env.SUPABASE_URL,
process.env.SUPABASE_ANON_KEY,
);
const signIn = async () => {
const { data, error } = await client.auth.signInWithPassword({
email: "hello@example.com",
password: "Developer123!",
});
};
await signIn();
const { data: exists, error: assetsError } = await client.storage.from(
"assets",
)
.exists(
"an-asset.webp",
);
console.log("(JWT client) Storage response error: ", assetsError);
};
main();
Yes, the 400 status code was a bit of a legacy decision to have a single status code for errors, however, we are going to fix it in the next major version of Storage
I don't have an exact timeline for this, but it is something we are actively changing for the next major release of Storage.
In the meantime, i'd be happy to help handle this error
Could you explain further what the problem you are encountering when trying to handle this error
Bug report
Describe the bug
When trying to check the existence of a file within a private storage bucket, if the RLS policy fails, a storage error of type
StorageUknownError
with HTTP status 400 is returned from the JavaScript client.To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
This should output something like this...
Expected behavior
I would expect an error of type "AccessDenied" or a HTTP status 403 to be returned as documented here.
System information
The text was updated successfully, but these errors were encountered: