Skip to content

Commit

Permalink
fix(slab): sanitize path concatenation on url
Browse files Browse the repository at this point in the history
  • Loading branch information
soonum committed Oct 24, 2024
1 parent 2f49f88 commit 5b5c0d2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
17 changes: 13 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions src/slab.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ function getSignature(content) {
return hmac.digest('hex')
}

function concat_path(url, path) {
if (url.endsWith('/')) {
// Multiple '/' char at the end of URL is fine.
return url.concat(path)
} else {
return url.concat('/', path)
}
}

async function startInstanceRequest() {
const url = config.input.slabUrl
const provider = config.input.backend
Expand All @@ -32,7 +41,7 @@ async function startInstanceRequest() {
try {
core.info(`Request ${provider} instance start`)

const response = await fetch(url.concat('/job'), {
const response = await fetch(concat_path(url, 'job'), {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -110,7 +119,7 @@ async function terminateInstanceRequest(runnerName) {
try {
core.info(`Request instance termination (runner: ${runnerName})`)

const response = await fetch(url.concat('/job'), {
const response = await fetch(concat_path(url, 'job'), {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -141,7 +150,7 @@ async function getTask(taskId) {
const url = config.input.slabUrl
const route = `task_status/${config.githubContext.repo}/${taskId}`

const response = await fetch(url.concat(route))
const response = await fetch(concat_path(url, route))
if (response.ok) {
core.debug('Instance task successfully fetched')
return response
Expand All @@ -161,7 +170,7 @@ async function removeTask(taskId) {
const url = config.input.slabUrl
const route = `task_delete/${config.githubContext.repo}/${taskId}`

const response = await fetch(url.concat(route), {
const response = await fetch(concat_path(url, route), {
method: 'DELETE'
})
if (response.ok) {
Expand Down

0 comments on commit 5b5c0d2

Please sign in to comment.