Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Feature: set 'credentials=include' to support additional CI systems #157

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/components/DataInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
:onNewReport="onNewReport"
v-if="reportSource === ReportSource.Url"
:presetUrl="this.presetUrl"
:includeCredentials="this.includeCredentials"
/>

<v-autocomplete
Expand Down Expand Up @@ -65,6 +66,7 @@ export default class DataInput extends Vue {
private reportSource = ReportSource.File
private ReportSource = ReportSource
@Prop() private presetUrl?: string
@Prop() private includeCredentials?: string
@Ref() readonly fileAgent!: {
deleteFileRecord: (fileRecordOrRaw: FileRecord) => void
}
Expand Down
40 changes: 39 additions & 1 deletion src/components/ReportUrlFetcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@
with the scope read_api.
</v-col>
</v-row>
<v-row>
<v-col>
<v-checkbox
v-model="setIncludeCredentials"
label="Send session credentials to remote host"
></v-checkbox>
</v-col>
</v-row>
<v-row>
<v-col>
If this flag is set, 'credentials=include' is set when
requesting the Trivy json. This allows downloading artifacts
from CI servers like Jenkins. This option can also be enabled
via the 'includeCredentials=true' url parameter. Don't forget to
configure CORS properly on the CI system, especially the related
<a
href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials"
>Access-Control-Allow-Credentials</a
>
header.
</v-col>
</v-row>
</v-container>
</v-card-text>
<v-card-actions>
Expand Down Expand Up @@ -84,6 +106,7 @@ const ReportUrlFetcherProps = Vue.extend({
props: {
onNewReport: Function,
presetUrl: String,
includeCredentials: String,
},
})
Vue.use(VueFileAgent)
Expand All @@ -92,12 +115,16 @@ Vue.use(VueFileAgent)
})
export default class ReportUrlFetcher extends ReportUrlFetcherProps {
private url = ""
private setIncludeCredentials = false
private state = "ready"
private dialog = false
private headerName = ""
private headerValue = ""
mounted(): void {
this.loadAuthorization()
if (this.includeCredentials) {
this.setIncludeCredentials = this.includeCredentials == "true"
}
if (this.presetUrl) {
this.url = this.presetUrl
this.fetchReportFromUrl()
Expand All @@ -106,10 +133,16 @@ export default class ReportUrlFetcher extends ReportUrlFetcherProps {
public loadAuthorization(): void {
this.headerName = localStorage.getItem("headerName") || ""
this.headerValue = localStorage.getItem("headerValue") || ""
this.setIncludeCredentials =
localStorage.getItem("includeCredentials") == "true"
}
public saveAuthorization(): void {
localStorage.setItem("headerName", this.headerName)
localStorage.setItem("headerValue", this.headerValue)
localStorage.setItem(
"includeCredentials",
this.setIncludeCredentials ? "true" : "false"
)
this.dialog = false
}

Expand All @@ -121,7 +154,12 @@ export default class ReportUrlFetcher extends ReportUrlFetcherProps {
headers[this.headerName] = this.headerValue
}
try {
const response = await fetch(this.url, { headers })
const fetchArgs: Record<string, string | object> = { headers }
if (this.setIncludeCredentials) {
fetchArgs["credentials"] = "include"
console.log("setting credentials")
}
const response = await fetch(this.url, fetchArgs)
this.state = "ready"
const contentType = response.headers.get("content-type")
if (
Expand Down
5 changes: 4 additions & 1 deletion src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ const routes: Array<RouteConfig> = [
path: "/",
name: "Home",
component: Home,
props: (route) => ({ presetUrl: route.query.url }),
props: (route) => ({
presetUrl: route.query.url,
includeCredentials: route.query.includeCredentials,
}),
},
{
path: "/about",
Expand Down
2 changes: 2 additions & 0 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<DataInput
@inputChanged="reactivelySetNewVulnerabilities"
:presetUrl="this.presetUrl"
:includeCredentials="this.includeCredentials"
/>
<DataTable :selectedVulnerabilities="selectedVulnerabilities"></DataTable>
</v-container>
Expand All @@ -44,6 +45,7 @@ import { Component, Prop } from "vue-property-decorator"
})
export default class Home extends Vue {
@Prop() private presetUrl?: string
@Prop() private includeCredentials?: string
private selectedVulnerabilities: Vulnerability[] = []

private reactivelySetNewVulnerabilities(newVulnerabilities: Vulnerability[]) {
Expand Down