Skip to content

Flags

Flag

Bases: ResponseModel

Represents a flag in CTFd.

Parameters:

Name Type Description Default
id int

The ID of the flag

required
type FlagType

The type of the flag

required
challenge int

Alias for challenge_id

required
challenge_id int

The ID of the challenge the flag is associated with

required
content str

The content of the flag

required
data str

Additional data for the flag, currently only supports "case_insensitive"

required

Attributes:

Name Type Description
id int

The ID of the flag, read-only

type FlagType

The type of the flag

challenge_id int

The ID of the challenge the flag is associated with

content str

The content of the flag

data str

Additional data for the flag, currently only supports "case_insensitive"

Properties

is_case_insensitive : bool Whether the flag is case-insensitive or not

Source code in ctfdpy\models\flags.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
class Flag(ResponseModel):
    """
    Represents a flag in CTFd.

    Parameters
    ----------
    id : int
        The ID of the flag
    type : FlagType
        The type of the flag
    challenge : int
        Alias for `challenge_id`
    challenge_id : int
        The ID of the challenge the flag is associated with
    content : str
        The content of the flag
    data : str
        Additional data for the flag, currently only supports `"case_insensitive"`

    Attributes
    ----------
    id : int
        The ID of the flag, read-only
    type : FlagType
        The type of the flag
    challenge_id : int
        The ID of the challenge the flag is associated with
    content : str
        The content of the flag
    data : str
        Additional data for the flag, currently only supports `"case_insensitive"`

    Properties
    ----------
    is_case_insensitive : bool
        Whether the flag is case-insensitive or not
    """

    id: int = Field(frozen=True, exclude=True)
    type: FlagType
    challenge_id: int = Field(
        validation_alias=AliasChoices("challenge_id", "challenge")
    )
    content: str
    data: Literal["case_insensitive", ""]
    templates: FlagTypeTemplatesDict | None = Field(None, exclude=True)

    @property
    def is_case_insensitive(self) -> bool:
        return self.data == "case_insensitive"

    def to_update_payload(self) -> UpdateFlagPayload:
        """
        Converts the flag to a payload for updating flags.

        Returns
        -------
        UpdateFlagPayload
            The payload for updating flags
        """
        return UpdateFlagPayload.model_validate(self, from_attributes=True)

to_update_payload

to_update_payload() -> UpdateFlagPayload

Converts the flag to a payload for updating flags.

Returns:

Type Description
UpdateFlagPayload

The payload for updating flags

Source code in ctfdpy\models\flags.py
69
70
71
72
73
74
75
76
77
78
def to_update_payload(self) -> UpdateFlagPayload:
    """
    Converts the flag to a payload for updating flags.

    Returns
    -------
    UpdateFlagPayload
        The payload for updating flags
    """
    return UpdateFlagPayload.model_validate(self, from_attributes=True)

FlagTypeInfo

Bases: ResponseModel

Information about the flag type.

This is used internally by CTFd to create the UI modals for creating and updating flags.

Parameters:

Name Type Description Default
name str

The name of the flag type

required
templates FlagTypeTemplatesDict

The templates for the flag type

required

Attributes:

Name Type Description
name str

The name of the flag type

templates FlagTypeTemplatesDict

The templates for the flag type

Source code in ctfdpy\models\flags.py
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
class FlagTypeInfo(ResponseModel):
    """
    Information about the flag type.

    This is used internally by CTFd to create the UI modals for creating
    and updating flags.

    Parameters
    ----------
    name : str
        The name of the flag type
    templates : FlagTypeTemplatesDict
        The templates for the flag type

    Attributes
    ----------
    name : str
        The name of the flag type
    templates : FlagTypeTemplatesDict
        The templates for the flag type
    """

    name: str
    templates: FlagTypeTemplatesDict

CreateFlagPayload

Bases: CreatePayloadModel

Payload to create a flag in CTFd.

Parameters:

Name Type Description Default
type FlagType

The type of the flag

required
challenge int

Alias for challenge_id

required
challenge_id int

The ID of the challenge the flag is associated with

required
content str

The content of the flag

required
data Literal['case_insensitive', '']

Additional data for the flag, currently only supports "case_insensitive"

required
Source code in ctfdpy\models\flags.py
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
class CreateFlagPayload(CreatePayloadModel):
    """
    Payload to create a flag in CTFd.

    Parameters
    ----------
    type : FlagType
        The type of the flag
    challenge : int
        Alias for `challenge_id`
    challenge_id : int
        The ID of the challenge the flag is associated with
    content : str
        The content of the flag
    data : Literal["case_insensitive", ""]
        Additional data for the flag, currently only supports `"case_insensitive"`
    """

    type: FlagType
    challenge_id: int = Field(
        validation_alias=AliasChoices("challenge_id", "challenge")
    )
    content: str
    data: Literal["case_insensitive", ""]

UpdateFlagPayload

Bases: UpdatePayloadModel

Payload to update a flag in CTFd.

Parameters:

Name Type Description Default
type FlagType

The type of the flag

required
challenge int

Alias for challenge_id

required
challenge_id int

The ID of the challenge the flag is associated with

required
content str

The content of the flag

required
data Literal['case_insensitive', '']

Additional data for the flag, currently only supports "case_insensitive"

required

Attributes:

Name Type Description
type FlagType

The type of the flag

challenge_id int

The ID of the challenge the flag is associated with

content str

The content of the flag

data Literal['case_insensitive', '']

Additional data for the flag, currently only supports "case_insensitive"

Source code in ctfdpy\models\flags.py
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
class UpdateFlagPayload(UpdatePayloadModel):
    """
    Payload to update a flag in CTFd.

    Parameters
    ----------
    type : FlagType
        The type of the flag
    challenge : int
        Alias for `challenge_id`
    challenge_id : int
        The ID of the challenge the flag is associated with
    content : str
        The content of the flag
    data : Literal["case_insensitive", ""]
        Additional data for the flag, currently only supports `"case_insensitive"`

    Attributes
    ----------
    type : FlagType
        The type of the flag
    challenge_id : int
        The ID of the challenge the flag is associated with
    content : str
        The content of the flag
    data : Literal["case_insensitive", ""]
        Additional data for the flag, currently only supports `"case_insensitive"`
    """

    type: FlagType = MISSING
    challenge_id: int = Field(
        MISSING, validation_alias=AliasChoices("challenge_id", "challenge")
    )
    content: str = MISSING
    data: Literal["case_insensitive", ""] = MISSING