-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: verify caller has access to attached files
- Loading branch information
1 parent
dd9faa7
commit aa500cf
Showing
7 changed files
with
151 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/com/epam/aidial/core/security/AccessService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.epam.aidial.core.security; | ||
|
||
import com.epam.aidial.core.ProxyContext; | ||
import com.epam.aidial.core.storage.BlobStorageUtil; | ||
import com.epam.aidial.core.util.UrlUtil; | ||
import lombok.AllArgsConstructor; | ||
|
||
@AllArgsConstructor | ||
public class AccessService { | ||
|
||
private final EncryptionService encryptionService; | ||
|
||
public boolean hasWriteAccess(String bucket, String filePath, ProxyContext context) { | ||
String urlDecodedBucket = UrlUtil.decodePath(bucket); | ||
String decryptedBucket = encryptionService.decrypt(urlDecodedBucket); | ||
String expectedUserBucket = BlobStorageUtil.buildUserBucket(context); | ||
if (expectedUserBucket.equals(decryptedBucket)) { | ||
return true; | ||
} | ||
String expectedAppDataBucket = BlobStorageUtil.buildAppDataBucket(context); | ||
if (expectedAppDataBucket != null && expectedAppDataBucket.equals(decryptedBucket)) { | ||
return filePath.startsWith(BlobStorageUtil.APPDATA_PATTERN.formatted(UrlUtil.encodePath(context.getSourceDeployment()))); | ||
} | ||
return false; | ||
} | ||
|
||
public boolean hasWriteAccess(String url, ProxyContext context) { | ||
if (url == null) { | ||
return false; | ||
} | ||
int index = url.indexOf(BlobStorageUtil.PATH_SEPARATOR); | ||
if (index < 0) { | ||
return false; | ||
} | ||
String bucket = url.substring(0, index); | ||
String path = url.substring(index + 1); | ||
return hasWriteAccess(bucket, path, context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters