Documentation
¶
Index ¶
- Variables
- func IsCookieInvalidated(cookie string) bool
- func IsCookieValid(cookie string, requestCount int) bool
- func ParsePixelHtmlVar(reader io.Reader) (int, error)
- func ParsePixelScriptURL(reader io.Reader) (string, string, error)
- func ParsePixelScriptVar(reader io.Reader) (string, error)
- func ParseScriptPath(reader io.Reader) (string, error)
- type SecCptChallenge
Constants ¶
This section is empty.
Variables ¶
var ( ErrPixelHtmlVarNotFound = errors.New("hyper-sdk: pixel HTML var not found") ErrPixelScriptUrlNotFound = errors.New("hyper-sdk: script URL not found") ErrPixelScriptVarNotFound = errors.New("hyper-sdk: script var not found") )
var (
ErrScriptPathNotFound = errors.New("hyper-sdk: script path not found")
)
var (
ErrSecCptParsing = errors.New("hyper-sdk: error parsing sec-cpt")
)
Functions ¶
func IsCookieInvalidated ¶
IsCookieInvalidated determines if the current session requires more sensors to be sent.
Protected endpoints can invalidate a session by setting a new _abck cookie that ends in '~0~-1~-1' or similar. This function returns if such an invalidated cookie is present, if it is present you should be able to make the cookie valid again with only 1 sensor post.
func IsCookieValid ¶
IsCookieValid determines if the provided _abck cookie value is valid, based on Akamai Bot Manager's client-side stop signal mechanism using the given request count. If the result is true, the client is ADVISED to halt further sensor data submissions. Submitting further would still produce a valid cookie but is unnecessary.
The stop signal mechanism in the Akamai Bot Manager's client-side script informs a client that the cookie received is valid and that any additional submissions are superfluous.
However, some applications do not activate the stop signal feature. In such scenarios, the client will continue submitting data whenever a trigger event occurs. Under these circumstances, verifying the authenticity of a cookie without sending it to a secured endpoint becomes challenging.
func ParsePixelHtmlVar ¶
ParsePixelHtmlVar gets the required pixel challenge variable from the given HTML code src.
func ParsePixelScriptURL ¶
ParsePixelScriptURL gets the script URL of the pixel challenge script and the URL to post a generated payload to from the given HTML code src.
func ParsePixelScriptVar ¶
ParsePixelScriptVar gets the dynamic value from the pixel script
Types ¶
type SecCptChallenge ¶
type SecCptChallenge struct {
Duration int
ChallengePath string
// contains filtered or unexported fields
}
func ParseSecCptChallenge ¶
func ParseSecCptChallenge(html io.Reader) (*SecCptChallenge, error)
ParseSecCptChallenge parses a sec-cpt challenge from an io.Reader.
The function extracts the challenge data, duration, and challenge path from the provided HTML content. It returns a *SecCptChallenge struct containing the parsed information and any error encountered during parsing.
Example usage:
html := `<iframe id="sec-cpt-if" provider="crypto" class="crypto" challenge="..." data-key="" data-duration=5 src="/_sec/cp_challenge/ak-challenge-4-3.htm"></iframe>`
challenge, err := ParseSecCptChallenge(strings.NewReader(html))
if err != nil {
// Handle the error
}
// Use the parsed challenge data
fmt.Println(challenge.Duration)
fmt.Println(challenge.ChallengePath)
Parameters:
- reader: An io.Reader containing the HTML content with the sec-cpt challenge.
Returns:
- *SecCptChallenge: A pointer to a SecCptChallenge struct containing the parsed challenge data, duration, and challenge path.
- error: An error encountered during parsing, or nil if parsing was successful.
Errors:
- ErrSecCptParsing: Returned when there is an error parsing the sec-cpt challenge data.
- Other errors may be returned by the underlying io.Reader or JSON unmarshaling.
func (*SecCptChallenge) GenerateSecCptPayload ¶
func (s *SecCptChallenge) GenerateSecCptPayload(secCptCookie string) ([]byte, error)
GenerateSecCptPayload generates the payload for the sec-cpt challenge.
The function takes the sec_cpt cookie value as input and extracts the necessary information to generate the payload. It generates the answers for the challenge using the `generateSecCptAnswers` function and creates an ordered object containing the token and answers.
Example usage:
secCptCookie := "..."
payload, err := challenge.GenerateSecCptPayload(secCptCookie)
if err != nil {
// Handle the error
}
// Use the generated payload
fmt.Println(string(payload))
Parameters:
- secCptCookie: A string representing the value of the sec_cpt cookie.
Returns:
- []byte: The generated payload as a byte slice.
- error: An error encountered during payload generation, or nil if generation was successful.
Errors:
- errors.New("error parsing sec_cpt cookie"): Returned when the sec_cpt cookie is not in the expected format.
- Other errors may be returned by the underlying JSON marshaling.
func (*SecCptChallenge) UpdateSecCptChallengeData ¶
func (s *SecCptChallenge) UpdateSecCptChallengeData(reader io.Reader) error
UpdateSecCptChallengeData updates the challenge data of a SecCptChallenge instance from an io.Reader.
The function reads the response body from the provided io.Reader, unmarshals it into a SecCptChallengeData struct, and updates the challengeData field of the SecCptChallenge instance with the new data.
Example usage:
resp, err := client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
if err := challenge.UpdateSecCptChallengeData(resp.Body); err != nil {
return err
}
Parameters:
- reader: An io.Reader containing the updated challenge data in JSON format.
Returns:
- error: An error encountered during reading the response body or unmarshalling the JSON data, or nil if the update was successful.
Errors:
- io.EOF: Returned when the response body is empty.
- Other errors may be returned by the underlying io.Reader or JSON unmarshalling.