Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
mclmax committed Oct 22, 2024
1 parent a744098 commit 0224edf
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 28 deletions.
14 changes: 1 addition & 13 deletions canarytokens/credit_card_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,13 @@ class Customer:

class CreditCardTrigger(BaseModel):
canarytoken: Canarytoken
auth_code: Optional[str]
billing_amount: Optional[str]
billing_currency: Optional[str]
card_id: Optional[str]
card_nickname: Optional[str]
client_data: Optional[str]
failure_reason: Optional[str]
masked_card_number: Optional[str]
merchant: Optional[dict]
network_transaction_id: Optional[str]
posted_date: Optional[str]
retrieval_ref: Optional[str]
status: Optional[str]
transaction_amount: Optional[str]
transaction_currency: Optional[str]
transaction_date: Optional[str]
transaction_id: Optional[str]
transaction_type: Optional[str]
risk_details: Optional[dict]
status: Optional[str]


def _get_lambda_client(refresh_client: bool = False):
Expand Down
4 changes: 4 additions & 0 deletions canarytokens/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1727,6 +1727,10 @@ class CreditCardV2AdditionalInfo(BaseModel):
merchant: Optional[dict]
transaction_amount: Optional[str]
transaction_currency: Optional[str]
masked_card_number: Optional[str]
transaction_date: Optional[str]
transaction_type: Optional[str]
status: Optional[str]


class CreditCardV2TokenHit(TokenHit):
Expand Down
17 changes: 15 additions & 2 deletions frontend_vue/src/components/HistoryToken.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@
<IncidentDetails
v-if="selectedAlert"
id="incident_detail"
:showingMap="showMap()"
:hit-alert="selectedAlert"
class="absolute top-[120px] left-[0] md:top-[0px] md:relative grid-areas z-10 md:overflow-scroll w-full sm:w-auto"
@close="selectedAlert = null"
></IncidentDetails>
</transition>
<CustomMap :hits-list="hitsList"></CustomMap>
<CustomMap v-if="showMap()" :hits-list="hitsList"></CustomMap>
</div>
<!-- Benner for larger screens -->
<BannerDeviceCanarytools class="hidden sm:flex" />
Expand All @@ -102,6 +103,7 @@ import BannerDeviceCanarytools from '@/components/ui/BannerDeviceCanarytools.vue
import IncidentDetails from '@/components/ui/IncidentDetails.vue';
import AlertsListDownload from '@/components/ui/AlertsListDownload.vue';
import { addViewTransition } from '@/utils/utils';
import { TOKENS_TYPE } from '@/components/constants';
const emits = defineEmits(['update-token-title']);
Expand All @@ -112,6 +114,7 @@ const isLoading = ref(false);
const error = ref(null);
const hitsList: Ref<HitsType[] | undefined> = ref();
const selectedAlert = ref();
const tokenType = ref();
onMounted(async () => {
await fetchTokenHistoryData();
Expand All @@ -129,12 +132,17 @@ async function fetchTokenHistoryData() {
const res = await historyToken(params);
const historyTokenData = (await res.data) as HistoryTokenBackendType;
hitsList.value = historyTokenData.history.hits.sort((a, b) => b.time_of_hit - a.time_of_hit);
tokenType.value = historyTokenData.history.token_type;
emits(
'update-token-title',
historyTokenData.history.token_type,
route.params.token
);
if (tokenType.value == TOKENS_TYPE.CREDIT_CARD_V2 && hitsList.value.length > 0) {
handleSelectAlert(hitsList.value[0]);
}
} catch (err: any) {
console.log(err, 'err!');
error.value = err.toString();
Expand All @@ -153,6 +161,11 @@ async function handleSelectAlert(incident: HitsType) {
: window.scrollTo({ top: 0, behavior: 'smooth' });
});
}
function showMap(): boolean {
const tokensWithoutGeoIPInfo = [TOKENS_TYPE.CREDIT_CARD_V2];
return !tokensWithoutGeoIPInfo.includes(tokenType.value);
}
</script>

<style>
Expand Down
17 changes: 13 additions & 4 deletions frontend_vue/src/components/ui/IncidentDetails.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<template>
<div class="pb-32 bg-white sm:m-8 rounded-3xl">
<div
class="pb-32 bg-white rounded-3xl"
:class="{ 'sm:m-8': props.showingMap, 'border shadow-solid-shadow-grey border-grey-100': !props.showingMap }">
<div class="sticky top-[0px] bg-white h-[4rem] sm:h-40 flex justify-end">
<button
v-if="props.showingMap"
type="button"
class="px-16"
@click="emit('close')"
Expand Down Expand Up @@ -113,10 +116,16 @@ import {
isNotEmpty,
buildIncidentDetails,
} from '@/utils/incidentAlertService';
import { boolean } from 'yup';
const props = defineProps<{
hitAlert: HitsType;
}>();
const props = withDefaults(
defineProps<{
hitAlert: HitsType;
showingMap: boolean;
}>(), {
showingMap: true,
},
);
const emit = defineEmits(['close']);
const builtIncidentDetail: Ref<FormattedHitsType | HitsType | null> = ref(null);
Expand Down
2 changes: 1 addition & 1 deletion frontend_vue/src/components/ui/IncidentDetailsSummary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<span class="text-xs text-red-100">Date</span>
<span class="font-semibold">{{ date }} </span>
</li>
<li class="flex flex-col gap-2">
<li v-if="ip" class="flex flex-col gap-2">
<span class="text-xs text-red-100">IP</span>
<span class="font-semibold">{{ ip }}</span>
</li>
Expand Down
25 changes: 17 additions & 8 deletions frontend_vue/src/utils/incidentAlertService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
INCIDENT_CHANNEL_TYPE_LABELS,
INCIDENT_DETAIL_CUSTOM_LABELS,
} from '@/components/constants';
import { useScrollLock } from '@vueuse/core';

/**
* Checks if the token type exists in INCIDENT_CHANNEL_TYPE_LABELS
Expand Down Expand Up @@ -127,6 +128,21 @@ function locationValue(
: location;
}

function parseGeoInfo(hitAlert: Record<string, any>) {
if (isCreditCardtoken(hitAlert.token_type)) return null;

if (!hitAlert.geo_info.bogon) {
return {
...hitAlert.geo_info,
}
}

return {
ip: hitAlert.geo_info.ip,
bogon: hitAlert.geo_info.bogon,
};
}

export function buildIncidentDetails(
hitAlert: HitsType
): FormattedHitsType | HitsType {
Expand All @@ -153,14 +169,7 @@ export function buildIncidentDetails(
},
time_of_hit: convertUnixTimeStampToDate(hitAlert.time_of_hit),
src_ip: hitAlert.src_ip,
geo_info: !hitAlert.geo_info.bogon
? {
...hitAlert.geo_info,
}
: {
ip: hitAlert.geo_info.ip,
bogon: hitAlert.geo_info.bogon,
},
geo_info: parseGeoInfo(hitAlert),
is_tor_relay: !isCreditCardtoken(hitAlert.token_type)
? hitAlert.is_tor_relay
: null,
Expand Down

0 comments on commit 0224edf

Please sign in to comment.