Skip to content

Commit

Permalink
Avoid two leading slashes in the request to create a new file (#22563)
Browse files Browse the repository at this point in the history
When using PFT+POP auth with ODSP, ODSP fails to validate the `p` field in the token when we have two leading slashes in the path. This is likely a bug in ODSP but it does result in cryptic 401 failure of the request.
  • Loading branch information
aboktor committed Sep 19, 2024
1 parent 0b17d50 commit a0b1e50
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/drivers/odsp-driver/src/createFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,22 @@ function extractShareLinkData(
return shareLinkInfo;
}

/**
* Encodes file path so it can be embedded in the request url
* @param path - path to encode
* @returns encoded path or "" if path is undefined
*/
function encodeFilePath(path: string | undefined): string {
return path ? encodeURIComponent(path.startsWith("/") ? path : `/${path}`) : "";
}

export async function createNewEmptyFluidFile(
getAuthHeader: InstrumentedStorageTokenFetcher,
newFileInfo: INewFileInfo,
logger: ITelemetryLoggerExt,
epochTracker: EpochTracker,
): Promise<string> {
const filePath = newFileInfo.filePath ? encodeURIComponent(`/${newFileInfo.filePath}`) : "";
const filePath = encodeFilePath(newFileInfo.filePath);
// add .tmp extension to empty file (host is expected to rename)
const encodedFilename = encodeURIComponent(`${newFileInfo.filename}.tmp`);
const initialUrl = `${getApiRoot(new URL(newFileInfo.siteUrl))}/drives/${
Expand Down Expand Up @@ -234,7 +243,7 @@ export async function createNewFluidFileFromSummary(
epochTracker: EpochTracker,
forceAccessTokenViaAuthorizationHeader: boolean,
): Promise<ICreateFileResponse> {
const filePath = newFileInfo.filePath ? encodeURIComponent(`/${newFileInfo.filePath}`) : "";
const filePath = encodeFilePath(newFileInfo.filePath);
const encodedFilename = encodeURIComponent(newFileInfo.filename);
const baseUrl =
`${getApiRoot(new URL(newFileInfo.siteUrl))}/drives/${newFileInfo.driveId}/items/root:` +
Expand Down

0 comments on commit a0b1e50

Please sign in to comment.